Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector to remove first X elements

I have a list with the following markup:

<div id="myList">
    <div data-role="collapsible">
            //...
    </div>

    <div data-role="collapsible">
            //...
    </div>

    //...

</div>

If I want to remove the first X (X is a specific number) childs of the list, which selector can I use in the following statement:

$("#myList").remove("???");
like image 723
amp Avatar asked Apr 24 '13 18:04

amp


People also ask

How do I remove the first 10 elements from a list in Python?

The pop() method removes an element at a given index, and will also return the removed item. You can also use the del keyword in Python to remove an element or slice from a list.

How do I remove the first 5 elements from a list in Java?

We can use the remove() method of ArrayList container in Java to remove the first element. ArrayList provides two overloaded remove() method: remove(int index) : Accept index of the object to be removed. We can pass the first element's index to the remove() method to delete the first element.

How do you remove the first element from a list in Python?

The remove() function allows you to remove the first instance of a specified value from the list. This can be used to remove the list's top item. Pick the first member from the list and feed it to the remove() function.


1 Answers

You can do this using slice():

$("#myList > div").slice(0,n).remove();

Where n is the amount of items you want to remove. FIDDLE

like image 111
palaѕн Avatar answered Oct 01 '22 20:10

palaѕн