Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one remove all <li> tags from a parent <ul> tag? [closed]

Tags:

jquery

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> 
like image 742
Saurabh Kumar Avatar asked Aug 04 '11 12:08

Saurabh Kumar


People also ask

How do I delete all Li in 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").

How do you clear the UL element?

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 .

Can Li tag be used without UL?

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> ).


2 Answers

try this instead there is no remove i guess$('#thickBoxProductLists').empty();

like image 85
Qchmqs Avatar answered Oct 21 '22 02:10

Qchmqs


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.

like image 25
Chuck Norris Avatar answered Oct 21 '22 02:10

Chuck Norris