I am creating a function where I could execute some jquery code …then pause for say… 5 secs and then execute something else..
Something like this:
function myFunc() {
var str1 = 'This is the starting text';
var str2 = 'This is the ending text';
$("#label").html(str1);
//I need a pause here (5000 ms) ---
$("#label").html(str2);
}
How can I get a pause in there?
This can be done sequentially using jQuery’s
queuemethodThe jQuery way:
Although it’s good to understand how to use
setTimeoutas well.The advantage to
queueis that it works by default along with thefxqueue, although you could choose to specify a different queue name.The non-jQuery way: