tags:

views:

28

answers:

1

Hello I have the following:

$('#container').prepend("<ul><li>Stuff</li></ul>').hide().slideDown();

I want the NEW UL to slide Down. but the above is sliding down the entire #container..

How can I prepend an item to the top, and then slide it down.. Kinda like how Twitter used to show you your new tweet.

Thank you.

+5  A: 

You can try using this syntax instead:

$('<ul><li>Stuff</li></ul>').prependTo('#container').hide().slideDown();

Of course, if you're using a list like that it might be useful to construct it element by element like this:

var ul = $('<ul />').prependTo('#container');
$('<li />').appendTo(ul).text('Incoming!').hide().slideDown();
Yi Jiang
Thanks the first one worked great. Thanks! Why construct it by element, that's more code?
@user It's not really more code in the sense that if you're going to do this for a lot of elements it quickly becomes a mess of string concatenations. The second method is useful for managing more complex stuff.
Yi Jiang
I'd make a small change and move the `.hide()` to before the prependTo/appendTo. Only to prevent any minute display before the hide (on slower JS engines)...
Alastair Pitts
@Alastair Good idea, though I have to admit I've never seen that before, even on IE
Yi Jiang
@Yi Jiang: Agreed, it's not very common, but I have run into it occasionally on IE. *shakes fist at IE*
Alastair Pitts