Javascript beginner: setTimeout hide/show issue?

javascript, jquery

Solution

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.

Problem

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.

Original source