SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    removeChild Problem

    Code:
    <table id="table-0">
         <tr id="table-0-0">
              <td>STUFF</td>
         </tr>
         <tr id="table-0-1">
              <td>STUFF</td>
         </tr>
    </table>
    and let's say i want to delete #table-0-1...

    Code:
    var parent = document.getElementById("table-0");
    var child = document.getElementById("table-0-1");
    parent.removeChild(child);
    but i get this error...

    Error: uncaught exception: [Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)"

  2. #2
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile This should work well ;)

    Hi,

    This should work well

    var child = document.getElementById("table-0-1");
    var parent = child.parentNode;
    parent.removeChild(parent.childNodes[0]);

    Cheers

    Kris

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't work right, because an anonymous <tbody> element is the parent of the <tr>, not the <table>.

    I'd do it like this:
    Code:
    var row = document.getElementById("table-0-1");
    row.parentNode.removeChild(row);
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Agree...

    I agree, it's a more robust solution.

    Thanks.

    Chris


Bookmarks

Posting Permissions

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