How I can add a css class to an element for only 10 seconds ?
A nicely reusable way would be this little jQuery plugin:
(function($){
    $.fn.extend({ 
        addTemporaryClass: function(className, duration) {
            var elements = this;
            setTimeout(function() {
                elements.removeClass(className);
            }, duration);
            return this.each(function() {
                $(this).addClass(className);
            });
        }
    });
})(jQuery);
Use like so:
$("#myElement").addTemporaryClass("myClass", 10000);
                        You can add the class, then call setTimeout(function() { ... }, 10000) to remove it 10,000 milliseconds later.
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