?
Solved

jQuery setTimeout

Posted on 2014-11-06
3
Medium Priority
?
306 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 2000 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)
Suggested Courses

770 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