views:

32

answers:

2

I'm trying to do the following method chain:

$(somehtml).insertAfter("#someelement").fadeIn('slow');

What I would like to happen is for the somehtml to be added but with the fadeIn effect.

However, this is not happening at all in my browser, it's just adding the contents as if the fadeIn wasn't even there.

Am I doing the chaining incorrectly?

+1  A: 

Probably because the element is already visible at that point, and there's nothing to fade in. Try hiding it after it was created, and then fading it in:

$(somehtml).hide().insertAfter("#someelement").fadeIn('slow');
Alec
That makes it blink. What I would like for it to do, is to start out hidden, and then show it.
Joseph
@Alec you were on the right track, this works: $(somehtml).hide().insertAfter("#someelement").fadeIn('slow');
Joseph
@Alec yup, that did it!
Joseph
I don't see a difference: http://jsfiddle.net/S2ttH/. But maybe it depends on what you're inserting and where.
Alec
A: 

Alec was on the right track, but you're going to get a flash of the element doing it the way he's demonstrating.

This is a much better way of doing the same thing:

$('<div />', {
  text: "Your Text",
  css: {
    display: "none"
  }
}).appendTo('body').fadeIn('slow');
coreyward