Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing li elements from ul

Is it possible using JavaScript to dynamically remove just a few li elements from a ul, given the id's of the li elements?

UPDATE about the actual issue:

I've the following list.

<ul id="attributes" data-role="listview">
    <li id="attrib01">Attribute1</li>
    <li id="attrib02">Attribute2</li>
    <li id="attrib03">Attribute3</li>
    <li id="attrib04">Attribute4</li>
    <li id="attrib05">Attribute5</li>
</ul>

After a ajax request/response, if a particular attribute is "undefined", I want to remove it from the list.

if(typeof data.attrib1 === "undefined")
    $("#attrib01").remove();

I've made sure I'm receiving the correct ajax response. So, the problem now is, that when I remove attrib4, attrib[1-3] are being removed as well. Any idea why this might be happening?

like image 562
Ashwin Avatar asked Aug 01 '12 00:08

Ashwin


1 Answers

Try

var elem = document.getElementById('id');
elem.parentNode.removeChild(elem);
like image 150
waldyr.ar Avatar answered Oct 18 '22 16:10

waldyr.ar