javascript remove li without removing ul?

MAZUMA

Is there any way to remove the li elements of a ul without also removing the ul? I can only seem to find this.

var element = document.getElementById('myList');
element.parentNode.removeChild(element);

But, this removes the ul. I'm hoping to be able to remove and append li elements on the fly without also having to createElement the ul every time I remove li elements. Just looking for a simpler way. Thanks for any help.

<div id="listView">
  <ul id="myList" class="myList-class">
    <li>item 1</li>
    <li>item 2</li>
  </ul>
</div>
Justin Wood

You can do something like this.

var myList = document.getElementById('myList');
myList.innerHTML = '';

If you are using jQuery

$('#myList').empty();

Both of these will remove EVERYTHING inside the list.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I remove my ul li first child without removing all the ul ul li first children?

From Dev

Add/remove <li> element from the ul javascript

From Dev

Tree using ul li and javascript without plugin

From Dev

Tree using ul li and javascript without plugin

From Dev

Add <li> to <ul> and remove <li> that is appended to <ul>

From Java

Removing black dots from li and ul

From Dev

Removing an LI from a UL via Angular

From Dev

Remove li from ul using id of li

From Dev

Add multiple Li to Ul with javascript

From Dev

javascript recursive ul li json

From Dev

Add multiple Li to Ul with javascript

From Dev

JavaScript how create <li> in <ul> and click on <li>

From Dev

JQuery click event remove ul li element

From Dev

Replace li with div and remove ul using jquery

From Dev

Jquery: remove last 4 "li" from ul

From Dev

In prototype how to remove li from ul

From Dev

How to remove all li from ul?

From Dev

How to remove border on ul li last child

From Dev

jquery remove class from li if there is no ul child

From Dev

How to target a certain element in ul and li in javascript DOM without any IDs

From Dev

JSON without keynames to ul li tag with jQuery

From Dev

.slideup() removing entire ul instead of just the nested li

From Dev

Removing dynamically created li containing mulitple sources from ul

From Dev

remove combined IBaction without removing

From Dev

Remove openjdk without removing tomcat

From Dev

Remove tags without removing content

From Java

how to add new <li> to <ul> onclick with javascript

From Dev

Check how many <li> there are in a <ul> with javascript

From Dev

How many li there are inside ul with javascript

Related Related

HotTag

Archive