Solved

jQuery setTimeout

Posted on 2014-11-06
3
294 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

813 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