Skip to content Skip to sidebar Skip to footer

How To Do Multiple SetTimeout JQuery In A Class?

i have a class called .content , this content has an attribute called .data-time, i want to hide all element where it has .content class with setTimeout() function, anybody can hel

Solution 1:

In your setTimeout function, this is the window. Try this instead:

http://jsfiddle.net/uXVAs/

$(".content" ).each(function(){
        var $this = $(this);
        var time = $this.data("time");
        setTimeout(function() {            
            $this.hide("slow");
        }, time);
    });

Solution 2:

Alternatively, you can use the .delay() jquery function.

$('.content').each(function(){
    var time = $(this).attr("data-time")
    $(this).delay(time).hide("slow")
});     

Example here.


Post a Comment for "How To Do Multiple SetTimeout JQuery In A Class?"