Given:
<ul id="myList" class="list-group"> <li>Remove Me 1</li> <li>Remove Me 2</li> <li>Remove Me 3</li> </ul>
I would like to remove all of the li children from a parent ul, so that when i do:
$("#myList").append("<li>New li 1</li>");
I end up with
<ul id="myList" class="list-group"> <li>New li 1</li> </ul>
Instead of:
<ul id="myList" class="list-group"> <li>Remove Me 1</li> <li>Remove Me 2</li> <li>Remove Me 3</li> <li>New li 1</li> </ul>
To remove all li elements from a ul element with JavaScript, we can set the innerHTML property of the ul element to an empty string. Then we write: document. getElementById("root").
First, get the ul element with the id menu by using the getElementById() method. Then, remove the last element of the ul element by using the removeChild() method. The menu. lastElementChild property returns the last child element of the menu .
The <li> HTML element is used to represent an item in a list. It must be contained in a parent element: an ordered list ( <ol> ), an unordered list ( <ul> ), or a menu ( <menu> ).
try this instead there is no remove i guess$('#thickBoxProductLists').empty();
If you have only li elements inside your ul
tag ,Jquery's remove()
function is all what you want.
But if you have other text or etc, use empty()
function.
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