Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top