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("???");
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.
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.
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.
You can do this using slice():
$("#myList > div").slice(0,n).remove();
Where n is the amount of items you want to remove. FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With