How could I clear the field message after a couple seconds using delay jQuery function instead of setTimeout? The code below will clear value immediately.
var $this = $(this),
mid = $this.find("#emid"),
contents = $this.find("#equestion");
if(contents.length<30){
contents.css('color','red')
.val('Error Message')
.delay(5000)
.val('');
}
UPD: Actually, you can simply use the default queue and freely chain effects (like
show) and non-effects (likeval). Just wrap the latter in aqueue–dequeuecall:http://jsfiddle.net/cA4jB/1/
/UPD
No, you don’t have to (and actually shouldn’t) use setTimeout. jQuery provides a nice built-in mechanism for this, called queue. The basic idea is like this: you “collect” functions or delays in a named queue:
and then call
dequeue()to start processing:Each function in the queue is called one after another, and delays work as expected.
In action: http://jsfiddle.net/cA4jB/