I have the following line of code:
var html = "...";
$("#id_name").append(html).fadeIn("slow");
This causes the entire div #id_name to fade in. I want only the appended HTML to fade in. How can this be accomplished?
I have the following line of code:
var html = "...";
$("#id_name").append(html).fadeIn("slow");
This causes the entire div #id_name to fade in. I want only the appended HTML to fade in. How can this be accomplished?
Share Improve this question edited Aug 11, 2009 at 19:15 VolkerK 96.2k20 gold badges167 silver badges231 bronze badges asked Aug 11, 2009 at 19:14 jackjack3 Answers
Reset to default 17You could do something like:
$('<div></div>').appendTo("#id_name").hide().append(html).fadeIn('slow');
you'd have to make sure the variable "html" is a jquery object first , and present in the DOM.
So you'd typically fire a callback function, fired when the append() is effective.
example:
$("#id_name").append(html,function(){
$(html).fadeIn("slow");
});
This should also work (assuming the html
var is a snippet of html code) and may be a bit more readable:
$(html).appendTo('#id_name').hide().fadeIn('slow');