1

Possible Duplicate:
jQuery: Can I call delay() between addClass() and such?

Hello I have an issue.

The below jQuery code is not working for me..

$("#message").addClass("highlightError").delay(15000).removeClass("highlightError");

What's the error?

The class in not even added..I checked with Firebug, no errors are shown..

Please help

Thanks!|

Community
  • 1
  • 1
DiegoP.
  • 45,177
  • 34
  • 89
  • 107

2 Answers2

3

removeClass is not used by the effects queue, so delay has no effect on it. To cause it to be called in the effects queue, manually add it using queue():

$(function(){
    $("#message").addClass("highlightError").delay(2000).queue(function(){
        $(this).removeClass("highlightError");
        $(this).dequeue();
    });
});

Works here: http://jsfiddle.net/QkpJn/1

gilly3
  • 87,962
  • 25
  • 144
  • 176
0

delay() method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed; for example this will not delay the no-arguments forms of .show() or .hide() which do not use the effects queue.

Refer to James Khoury's link to see how you can make custom queues

makeitmorehuman
  • 11,287
  • 3
  • 52
  • 76