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.
If you have it applied to an element but want to remove it from an element after a designated amount of time has passed, you can do so by using jQuery's . setTimeout() method. var header = $('#header'); header. addClass('blue'); setTimeout(function() { header.
Free jQuery snippet to remove class from an element after delay of a few seconds. This snippet uses setTimeout function to delay the execution of the script. To remove class we simply use removeClass jQuery function.
removeClass() Method. This method removes one or more class names from the selected elements. If no parameter is specified in the removeClass() method, it will remove all class names from the selected elements.
The addClass() method adds one or more class names to the selected elements. This method does not remove existing class attributes, it only adds one or more class names to the class attribute. Tip: To add more than one class, separate the class names with spaces.
Use setTimeout. Also not sure why you are binding to click twice in two different ways... so with those two changes it'd look something like this:
$("#loadmore").click(function() {
cap += 10;
loadfeed();
$(this).addClass("loading");
that = this
setTimeout(function() {
$(that).removeClass('loading');
}, 10000)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With