Solved

jQuery setTimeout

Posted on 2014-11-06
3
297 Views
Last Modified: 2014-11-06
Hello Experts,

I am using the "setTimeout" function to add a class to a preloader element.
I want to remove the element from the page after 1s.

The first code is the initial and the second is what does not work for removing the element.

Can you please let me know how to "callback" after the 1s and remove the "#loader" element from the DOM?

setTimeout(function() {
    $("#loader").addClass("loaded")
 } ,1000);

Open in new window



setTimeout(function() {
    $("#loader").addClass("loaded")
 } ,1000, function() {
   $("#loader").remove();
});

Open in new window

0
Comment
Question by:Refael
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40427164
use two instead one :

setTimeout(function() {
    $("#loader").addClass("loaded")
 } ,1000);
setTimeout(function() {
    $("#loader").remove();
 } ,2000);

Open in new window

0
 

Author Closing Comment

by:Refael
ID: 40427183
leakim971 as always you are a star :-)
I thought there is a way to combine one function with the "remove". Okay i will have two functions instead.
Many thanks!!!
0
 

Author Comment

by:Refael
ID: 40427184
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question