删除当前元素节点

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/example/xdom/loadxmldoc.js">
  4. </script>
  5. </head>
  6. <body>
  7. <script type="text/javascript">
  8. xmlDoc=loadXMLDoc("/example/xdom/books.xml");
  9.  
  10. document.write("removeChild() 方法执行前 book 节点的数目:");
  11. document.write(xmlDoc.getElementsByTagName("book").length);
  12. document.write("<br />");
  13.  
  14. x=xmlDoc.getElementsByTagName("book")[0]
  15. x.parentNode.removeChild(x);
  16.  
  17. document.write("removeChild() 方法执行后 book 节点的数目:");
  18. document.write(xmlDoc.getElementsByTagName("book").length);
  19.  
  20. </script>
  21. </body>
  22. </html>