Friday, May 6, 2011

JQuery fadeIn() on DOM element creation?

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!

From stackoverflow
  • Add it with a class which is hidden at the start.

    <style>
    .hidden {
      display:none;
    }
    </style>
    
    <div class="hidden">
     Won't be seen.
    </div>
    
  • $("<div>Hello</div>").hide().appendTo("somePlace").fadeIn("fast");
    
    altCognito : +1 Sigh. Oh yeah, good point.
    Jasie : Thanks cletus! Thanks altCognito for the alternative.

0 comments:

Post a Comment