views:

38

answers:

3

this is my current code

 $('ul#attachmentlist>li').last().after("<li>new item on list</li>");
 $('ul#attachmentlist>li').last().effect("highlight", {}, 2000);

what i want is to have the newly inserted li element get highlighted after it is sorted

 $('ul#attachmentlist>li').last().after("new item on list");
 $("ul#attachmentlist>li").tsort(); // tinysort plugin
 $('ul#attachmentlist>li').last().effect("highlight", {}, 2000);

i have sorting working, how do i get a reference to the newly inserted item, so that when i call the highlight effect, it highlights the newly inserted element, not the last one on the list ?

thanks

A: 

What if you created the object before inserting it? Then you'd have the correct reference to highlight:

var newListItem = $("<li>new item on list</li>");
$('ul#attachmentlist>li').last().after(newListItem);
$("ul#attachmentlist>li").tsort(); // tinysort plugin
newListItem.effect("highlight", {}, 2000);
Pat
thanks, i knew they had to be a simple way of doing it
bumperbox
A: 

You could give the added Li a class, then remove it after you highlight it. like so:

 $('ul#attachmentlist>li').last().after("<li class='NewThing'>new item on list</li>");
 $("ul#attachmentlist>li").tsort(); // tinysort plugin
 $('ul#attachmentlist>li').find('.NewThing').effect("highlight", {}, 2000).removeClass('NewThing');
Patricia
This will add a class to the *previous* last item, not the newly inserted element.
Nick Craver
damn, that's right. that's what i get for trying to keep the solution close to the original. Your solution is better!
Patricia
i fixed my answer, just incase someone comes across this in the future
Patricia
+1  A: 

You can kick off the effect animation before the sort keeping it still pretty simple, like this:

$("<li>new item on list</li>").appendTo('ul#attachmentlist')
                              .effect("highlight", {}, 2000);
$('ul#attachmentlist>li').tsort();

This uses the $(html) method of creating the element, and just appending it to the parent (thereby making it the last item) and starting an animation at the same time. Then we do a sort...but the animation will continue to work, even after the elements are sorted.

Nick Craver