...

View Full Version : how do I remove an li?



shedokan
08-25-2008, 03:22 AM
I am unable to find the piece of code to remove li from a list.
I only found codes for lists and something like removeChild.
please help.
thanks.

Arbitrator
08-25-2008, 07:01 AM
I am unable to find the piece of code to remove li from a list.
I only found codes for lists and something like removeChild.
please help.Youíve been so unspecific that one can only give you an unspecific answer:

Example HTML Fragment

<li id="item">List Item</li>

Example Script Fragment

var item = document.getElementById("item");
item.parentNode.removeChild(item);

shedokan
08-25-2008, 05:42 PM
sorry for being unspecific, like I said before I found a script just like you gave me but the problem is that if I have a ul with more than one li so it wouldn't work.
here's the ul I'm working with:

<ul id="menu">
<li id="item_5">Cheats<a onlick="Remove('item_5'); return false;" href="#">Remove</a></li>

<li id="item_1">Item 1</li>
<li id="item_4">Item 2</li>
<li id="item_3">Item 3</li>
<li id="item_2">Item 4</li>
</ul>

JUD
08-25-2008, 10:43 PM
http://www.hull101.co.uk/test_area/removeListItem.html

Arbitrator
08-26-2008, 04:05 AM
sorry for being unspecific, like I said before I found a script just like you gave me but the problem is that if I have a ul with more than one li so it wouldn't work.Yes, it will. You donít seem to have done any research into how removeChild works.

In the theme of my previous code, you can use onclick="var item = document.getElementById('item_5'); item.parentNode.removeChild(item);". To be more direct, you can use onclick="document.getElementById('menu').removeChild(document.getElementById('item_5'));". If you want to remove items by index (so, for example, you donít have to assign each li element an ID), you could use onclick="var menu = document.getElementById('menu'); menu.removeChild(menu.getElementsByTagName('li').item(0));".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum