SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: replaceNode() ;

  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replaceNode() ;

    I found the following code here
    But it don't work on Opera 9.1 and Firefox 2.0.0.1
    Code:
      
    <html>
    <body>
    <script type="text/javaScript">
    function function1() {
       var newElement = document.createElement('u');
       newElement.innerHTML = 'Text';
       var oldElement = document.all.myBold;
       document.all.myBold.replaceNode(newElement); 
    } 
    </script>
    <button onclick="function1();">Replace text</button>
    <div id="myDiv" style="width:300; height:200; border:solid black 1px;">Sample 
        <b id="myBold">text</b>
    </div>
    </body>
    </html>
    I use getElementById():
    Code:
      
    <html>
    <body>
    <script type="text/javaScript">
    function function1() {
       var newElement = document.createElement('u');
       newElement.innerHTML = 'New Text';
       var oldElement = document.getElementById('myBold');
       oldElement.replaceNode(newElement); 
    } 
    </script>
    <button onclick="function1();">Replace text</button>
    <div id="myDiv" style="width:300; height:200; border:solid black 1px;">Sample 
        <b id="myBold">Old text</b>
    </div>
    </body>
    </html>
    The same things happen.
    How will it work on Firefox and Opera? Thanks...
    Last edited by muazzez; Feb 4, 2007 at 13:37.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.all and replaceNode() are not part of the W3C DOM.

    You want replaceChild().

    Code:
    oldElement.parentNode.replaceChild(newElement,oldElement);
    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.


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
  •