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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    removing a div vased on (id) from a split() match....

    [html]
    <script Language="JavaScript">
    function removeElement(ele){
    pieces = ele.split("_");
    var ele = pieces[0]; ele.parentNode.removeChild(ele);
    }
    </script>

    <div id="1">Industrial Goods <input type="button" value="Delete" onClick="removeElement(1_1)"> <br> </div>
    [/html]

    So, the div ID is "1" and the variable passed is 1_1, I want to split 1_2 ( using the underscore to split it) > then use the splitpiece[0] to identify the div="1" tag and delete it.....

    But it isnt working for some reason...

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    1_1 is a string and must be enclosed in quotes. '1_1'

    <script type = "text/javascript">
    function removeElement(ele){
    pieces = ele.split("_");
    var ele = pieces[0];
    ele.parentNode.removeChild(ele);
    }
    </script>

    <div id="1">Industrial Goods <input type="button" value="Delete" onClick="removeElement('1_1')"> <br> </div>



    I may not be perfect, but parts of me are excellent.
    Last edited by Philip M; 09-07-2008 at 10:10 AM.


  •  

    Posting Permissions

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