Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript beginner: setTimeout hide/show issue?

I am trying to hide an element after 2000ms by the below code.

setTimeout($templateElement.hide(),2000);

I am the new one to jquery and java-script. I hope Anyone clear my doubts.

like image 518
yuva Avatar asked Jan 17 '23 00:01

yuva


1 Answers

The code

setTimeout($templateElement.hide(),2000);

executes the $templateElement.hide() immediately and passes its return value (a jQuery object) into setTimeout. You may have meant:

setTimeout(function() {
    $templateElement.hide();
}, 2000);

...which passes a function reference into setTimeout, to be called two seconds later. That function then does the hide when it gets called.

like image 176
T.J. Crowder Avatar answered Jan 25 '23 22:01

T.J. Crowder