'Time between jQuery add/remove class

How can I set a timer, 10 sec in between this?

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

This is the full code

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

Thank you.



Solution 1:[1]

You can use the jQUery delay() method and create a new queue item to do the act of removing 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 that @jcmoney provided is awesome.

Solution 2:[2]

$(document).ready(function() {                      
  $('.letsGo').click(function() { 
    $('.footerCta').addClass('ball');  
    setTimeout(function() {
        $('.footerCta').removeClass('ball');
    }, 1000)
  });
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fisher Evans
Solution 2 Rajat Kumar