Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Question how do I remove an li?

    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.

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by shedokan View Post
    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
    Code:
    <li id="item">List Item</li>
    Example Script Fragment
    Code:
    var item = document.getElementById("item");
    item.parentNode.removeChild(item);
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #3
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    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:
    Code:
    <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>

  • #4
    JUD
    JUD is offline
    New Coder
    Join Date
    Jul 2005
    Location
    I'm right here
    Posts
    92
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Last edited by JUD; 08-25-2008 at 10:30 PM.

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by shedokan View Post
    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));".
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •