Question

I have a list of items in the DOM and would like to prune it to only contain the first N items, perhaps using slice and remove.

What is the syntax in JQuery to remove any items after the first N?

Était-ce utile?

La solution

It seems like you are looking for something like this:

JSFiddle

$("body").children().filter(":gt(5)").remove();

The above removes all the direct children of body with an index over 5. This is assuming body is the top of the DOM in question. if not, you can change body to be whatever the head of the DOM you want to "prune" is.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top