JQuery fadeIn() on DOM element creation?

atp picture atp · May 11, 2009 · Viewed 7.7k times · Source

How do I create a DOM element in JQuery and fade it in to show up, instead of having it show up immediately?

I try this:

var myDiv = "<div>Hello!</div>"
$("somePlace").after(myDiv).fadeIn('fast');

but this doesn't work, since the .after(myDiv) makes it popup immediately. Any solutions? Thanks!

Answer

cletus picture cletus · May 11, 2009
$("<div>Hello</div>").hide().appendTo("somePlace").fadeIn("fast");