Time between jQuery add / remove class

How to set a timer in 10 seconds?

addClass('loading').removeClass('loading') 

This is the complete code.

 $("#loadmore").click(function() { cap += 10; }).bind('click', loadfeed).addClass('loading').removeClass('loading'); 

Thanks.

+4
source share
3 answers

Use setTimeout . Also not sure why you are attached to the click twice in two different ways ... so with these two changes it would look something like this:

 $("#loadmore").click(function() { cap += 10; loadfeed(); $(this).addClass("loading"); that = this setTimeout(function() { $(that).removeClass('loading'); }, 10000) }); 
+10
source

You can use the jQUery delay () method and create a new queue to perform the action to remove the class.

 $("#loadmore").click(function () { cap += 10; loadfeed(); }).addClass("loading").delay(10000).queue(function(){ $(this).removeClass("loading"); $(this).dequeue(); }); 

If you don't like this, the setTimeout() solution provided by @jcmoney is awesome.

+9
source

Using this is much better if you want jQuery on a single line:

http://api.jquery.com/delay/

0
source

All Articles