Luca Luca - 11 months ago 47
jQuery Question

delay() and fadeOut() don't delay attr() in the queue

what is wrong in this code? I'm trying to get this effect:

delayed by 600 millisecs.. then
again, and
. The delays happen correctly but the
is not being delayed, it fires when
is still fading! :'(


Answer Source

The .delay() only affects the animation or fx queue (unless you specify a different queue specifically). Keep in mind that chaining and queuing are 2 distinctly different concepts, chaining continues the use of the same jquery set, but that's a different thing entirely than any event queues on elements in that set.

To have the .attr() call affected, you have to add it as a callback to that same queue using .queue(), like this:

           .queue(function(next) { $(this).attr('class','myClass'); next(); })

Also note there are .addClass(), .removeClass() and .toggleClass() methods available that may make this a bit cleaner :)