Search code examples
jquerydomfade

Creating a DOM element on the fly, but fading it in


I'm having a problem creating a DOM element, appending it to another element and having it fade into place.

This doesn't seem to work:

$('<div/>').html('hello').appendTo('#parentDiv').fadeIn();

Can anybody put me on the right track


Solution

  • Try:

    $("<div>hello</div>").hide().appendTo("#parentDiv").fadeIn();
    

    or alternatively set display none instead of hide().