Javascript beginner: setTimeout hide / show issue?

I am trying to hide an item after 2000ms with the following code.

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

I am new to jquery and java-script. I hope someone clears my doubts.

+4
source share
1 answer

Code

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

executes $templateElement.hide() immediately and passes its return value (jQuery object) to setTimeout . Did you mean:

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

... which passes the reference to the function in setTimeout , which will be called after two seconds. This function then performs hide on invocation.

+9
source

All Articles