javascript - Wait for function to finish -


i have function called opslaanmelding()

in function insert div text , want let display none after 3 secs. think other function refreshing page time out doens't work

any idea wait function finish , let him continue?

this code :

innerdiv.innerhtml = term; innerdiv.classname = 'classname'; innerdiv.id = 'myid'; console.log(innerdiv.getwidth()); innerdiv.style.marginleft =  width- 80 + "px";  innerdiv.style.margintop = "7px"; $('header').insert({after: innerdiv}) settimeout(function() {    // display none after 3 secs     window.document.getelementbyid('myid').style.display = 'none'; },3000);  

any idea wait function finish , let him continue

you can't prevent function returning 3 seconds without locking ui of browser (and/or getting "slow script" error), of course prevent content appearing , not want.

instead, have function accept callback calls when 3 seconds up, , put whatever follows callback rather running immediately.

e.g., instead of:

yourfunction(); dosomething(); dosomethingelse(); 

make it

yourfunction(function() {     dosomething();     dosomethingelse(); }); 

...and modify function follows:

function yourfunction(callback) {   // **** note `callback` argument     innerdiv.innerhtml = term;     innerdiv.classname = 'classname';     innerdiv.id = 'myid';     console.log(innerdiv.getwidth());     innerdiv.style.marginleft =  width- 80 + "px";      innerdiv.style.margintop = "7px";     $('header').insert({after: innerdiv})     settimeout(function() {         // display none after 3 secs         window.document.getelementbyid('myid').style.display = 'none';          // *************** callback         callback();     },3000); } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -