yuva
yuva

Reputation: 107

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.

Upvotes: 4

Views: 5957

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075309

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.

Upvotes: 10

Related Questions