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.
  • 43,947
  • 34
  • 88
  • 105

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
  • 83,908
  • 25
  • 139
  • 172
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

Ali Habibzadeh
  • 10,646
  • 3
  • 50
  • 72