Reputation: 3062
I am trying to display the two alert box in two different time intervals
<script>
function myFunction()
{
setTimeout(function(){alert("Hello")},3000);
setTimeout(function(){alert("Hello World")},3000);
}
</script>
I want to display Hello alert after 3 sec and Hello World after 3 sec of 1st alert, but 2nd alert displaying immediate to 1st one.
How to make it work?
Thank You
Upvotes: 1
Views: 1186
Reputation: 12325
Put the second setTimeout in the first one. Like this...
setTimeout(function(){
alert("Hello");
setTimeout(function(){alert("Hello World")},3000);
},3000);
Upvotes: 1
Reputation: 2629
You can nest a timeout in the function of the first one:
setTimeout(function(){
alert("Hello");
setTimeout(function(){alert("Hello World")},3000);
},3000);
Upvotes: 5