Good tip, but don't use the string version: setTimeout("e.show(200);", 1000);
Use the function version: setTimeout(function() { e.show(200); }, 1000); When you pass a string to setTimeout() or setInterval(), the code is executed in the *global context*. If the code is inside a function and the variable 'e' is local to that function, the string version won't work. e will be undefined. The function version uses a closure to give the timeout function access to local variables in the calling function. -Mike On Tue, Oct 6, 2009 at 12:02 PM, James <james.gp....@gmail.com> wrote: > > setTimeout(e.show(200), 1000); > > should be: > > setTimeout("e.show(200);", 1000); > > or: > > setTimeout(function() { > e.show(200); > }, 1000); > > (line-end semi-colon not necessary, but should be used for good > practice) > > On Oct 6, 7:57 am, Dennis Madsen <den...@demaweb.dk> wrote: > > I'm trying to create new DOM and append it to a div. When the div is > > appended, I would like it to be shown after 1sec. > > > > var e = "<div style='display:none;'>content</div>"; > > $("#container").append(e); > > setTimeout(e.show(200), 1000); > > > > This code does not work. The HTML is appended but the show-function > > does not work. Hope someone can help me. >