Ronal
Ronal

Reputation: 2243

Jquery .remove() undo?

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.

Upvotes: 4

Views: 6851

Answers (4)

Elzo Valugi
Elzo Valugi

Reputation: 27876

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

Upvotes: 1

Boldewyn
Boldewyn

Reputation: 82784

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,

Upvotes: 6

Max Schmeling
Max Schmeling

Reputation: 12509

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().

Upvotes: 1

helloandre
helloandre

Reputation: 10721

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

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

Upvotes: 7

Related Questions