tags:

views:

373

answers:

4

Is there any way to achieve this? I am using a pagination plugin that reads the number of li's inside my ul and determines the number of numbered links to spit out.

+4  A: 

You probably want to use .hide() and check to see if the li is visible or not.

This can be done with $("li:visible")

contagious
Simple, yet beautiful ;-) +1
Boldewyn
li:visible wont do the trick for me as i need the element removed from the <ul>
Ronal
but if you make display:none with .hide() and find all the visible ones, it effectively is removed. jquery won't find it, and it's not visible to the user.
contagious
A: 

There isn't any way to do it that I can think of without modifying the jQuery code. It probabl wouldn't be that hard to modify though. You would need to put in a stack (or stack like structure) and when .remove() is called, put the html in there along with the selector or something like that, and then on .undo(), put it back.

This is assuming you really need undo capabilities and not just the ability to toggle visibility with .hide()/.show() or .toggle().

Max Schmeling
+2  A: 

See jQuery's docs:

$("#foo").remove().appendTo("#bar");

If #foo was a child of #bar, the above line doesn't have any effect. Now, storing $("#foo").remove() in a variable (it's a jQuery object) and re-appending it is left over to you as exercise ;-)

Cheers,

Boldewyn
Thanks Boldewin! This definitely helped
Ronal
You're welcome.
Boldewyn
A: 

If you want a semantic undo to remove(), that will be append(). But you want probably what @contagious and @Max Schmeling suggested, a toggle().

Elzo Valugi