Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  17] [ 4]  / answers: 1 / hits: 64976  / 9 Years ago, thu, may 21, 2015, 12:00:00

How to make it work? pls help.



function first() {
setTimeout((function() {
$('#q').append('first <br>');
}), 1000);
}
function second() {
$('#q').append('second <br>');
}
function third() {
$('#q').append('third <br>');
}
$.when(first()).done(second()).done(third());


first() runs as last function, i need as first



Fiddle here: JSFIDDLE


More From » jquery

 Answers
83

I am not sure why are you doing this, but if you want to execute them synchronously, you can place the 2nd and 3rd function call inside setTimeout :



function first() {
setTimeout(function() {
$('#q').append('first <br>');
second();
third();
}, 1000);
}
function second() {
$('#q').append('second <br>');
}
function third() {
$('#q').append('third <br>');
}
first();

[#66518] Tuesday, May 19, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
heidys

Total Points: 665
Total Questions: 102
Total Answers: 97

Location: Belarus
Member since Sat, Jul 18, 2020
4 Years ago
;