Javascript examples for DOM:Document getElementById
parse a document and remove all elements except for one that matches and ID and its children
<html> <head></head> <body> eee // w w w .ja v a2 s . co m <div id="my"> A <div> B </div> C </div> <span>D</span> <script> var saved = document.getElementById('my'); var elms = document.body.childNodes; while (elms.length) elms[0].parentNode.removeChild(elms[0]); document.body.appendChild(saved); </script> </body> </html>