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 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    50
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Changing the nodeValue

    Hi,

    I am having trouble with the nodeValue. I am trying to change a particular value to a different text, this is a snippet of my code.....

    function clickme1() {
    objB = document.getElementById('therow');
    objB.secondChild.nodeValue="Text change!";
    }
    </script>

    The table is here...

    <table border="thin">
    <tr><td onclick="clickme();" class="one"><input type="button" value="Make it smile!"/></td><td onclick="clickme1();" class="two"><input type="button" value="Make it smile twice!"/></td><td onclick="clickme2();" class="three"><input type="button" value="Make it empty!"/></td></tr>
    <tr id="therow"><td class="one">First cell</td><td class="two">Second cell</td><td class="three">Third cell</td></tr>
    <tr span="3"><td onclick="clickme3();"><input type="button" value="Reload page"/></td></tr>
    </table>

    Could anyone guide me in the right direction as to what needs to be changed for the new nodeValue to appear on click?

    Thanks very much

  • #2
    New Coder
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Buckster_uk
    function clickme1() {
    objB = document.getElementById('therow');
    objB.secondChild.nodeValue="Text change!";
    }

    <tr id="therow"><td class="one">First cell</td><td class="two">Second cell</td><td class="three">Third cell</td></tr>
    secondChild isn't an object. I guess you wanted the second td, you can get that using objB.firstChild.nextSibling, or objB.getElementsByTagName('td')[1].
    Also, if you want to change the text of the td, the td actually contains a text node, so you would have to change td.firstChild.nodeValue instead of just td.nodeValue.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    better use

    root.getElemensByTagName('the_tag')[index]

    that the firstChild or firstChild.next Sibling, as there are differences between IE and Moz when counting the childs the momemnt when the textNode is empty or there is a wrap in HTML coding of the tags.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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