Solved

jQuery setTimeout

Posted on 2014-11-06
3
284 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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now