Results 1 to 1 of 1

Thread: Replacing innerHTML with valid DOM

  1. #1
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default Replacing innerHTML with valid DOM

    I'm testing the following script for including and removing HTML:
    Code:
    <script type="text/javascript">
    
    function remove(id)
    {
    while(document.getElementById(id).firstChild)
    {document.getElementById(id).removeChild(document.getElementById(id).firstChild);}
    }
    function include(which,id){
    var newdiv = document.createElement("div");
    newdiv.innerHTML = which;
    remove(id); document.getElementById(id).appendChild(newdiv);
    }
    </script>
    
    </head>
    
    <body>
    <div id="test"></div>
    <a onclick='include(whatever,"test");'>add</a><br>
    <a onclick='remove("test")'>remove</a><br>
    
    </body>
    I'd like to replace the line in red with a line using valid DOM.
    Any suggestions?
    ===
    Arie Molendijk.
    Last edited by molendijk; 04-12-2010 at 01:29 PM. Reason: Correction

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
  •