Im trying to make my program just chill out for 3 sekunds and then proceed with the rest of the code - but all the stuff i can finde online just delays specifit lines of code (any way not what i was looking for)
What i wish to do is something like this
$("#one").attr("id","H1");
$("#line1").attr("id","line2");
setTimeout(3000);
$("#line2").attr("id","line1");
$("#H1").attr("id","two");
And it should just chillout for 3 sekunds where i have placed the settimeout(3000); but can make it work ? im i missing something obvious ?
Thanks alot ! :D
Normally when someone wants JavaScript, which is a single-thread event-based model, to sleep, they do not quite understand the language.
You are not supposed to block code. Instead, you should make use of callbacks, event triggers or Promises to run dependent code when you have the dependencies.
Please read through this entire question so that you understand better what it is you are trying to do, and then decide which action to take.