Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

DOM manipulation question

Options
  • 30-07-2002 12:15pm
    #1
    Registered Users Posts: 14,148 ✭✭✭✭


    Hey guys,

    I've got a minor problem here regarding IE and DOM. I can get it working with the likes of NS, and I'm following the exact DOM specs.

    Simply, I have a table cell in which I am checking to see if a childNode (in this case a "textNode") exists, and if so to delete it.

    Then it creates a new textNode and appends it to the Parent Node (in this case a 'b' tag inside the cell)

    Here's the code
    <script type="text/javascript>
    <!-- 
    
    function alterNode(option)
    {
       if(document.getElementById('dependentText').childNodes.length != null)
       {
          var node = document.getElementById('dependentText') ;
          node.removeChild(node.childNodes[0]) ;
       }
    
       if(option == 'blah')
          var x = document.createTextNode('Option1: ') ;
       else
          if(option == 'blahblah')
             var x = document.createTextNode('Option2: ') ;
    
       document.getElementById('dependentText').appendChild(x) ;
    }
    
    //-->
    <script>
    
    <body>
       <table>
          <tr>
             ......
             <td>
                 <b id="dependentText"></b>
             </td>
             ...... 
          </tr> 
       </table>
    </body>
    


    Now, as I said .. it all works except in IE, which seems to have a hang up with the (node.childNodes[0]) reference in node.removeChild()

    Any ideas?


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    It's because node.childNodes[0] is null, you need to test it first
    if (null != node.childNodes[0])
       node.removeChild(node.childNodes[0]);
    


Advertisement