Joseph
Joseph

Reputation: 25523

Does chaining in jQuery work with manipulation and effect methods?

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?

Upvotes: 2

Views: 174

Answers (2)

coreyward
coreyward

Reputation: 80090

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');

Upvotes: 0

Alec
Alec

Reputation: 9078

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');

Upvotes: 1

Related Questions