Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top