code:
<html> <head> <title>Introduction to the DOM</title> </head> <body> <h1>Introduction to the DOM</h1> <p class="test">There are a number of reasons why the DOM is awesome, here are some:</p> <ul> <li id="everywhere">It can be found everywhere.</li> <li id="test">It‘s easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> </ul> <script> //直到文档完全载入,我们才能操作 DOM window.onload = function() { //找到文档中所有的<li>元素 var li = document.getElementsByTagName("li"); //然后给它们全部加上边框 for ( var j = 0; j< li.length; j++ ) { li[j].style.border = "1px solid #000"; } //定位 ID 为‘everywhere‘的元素 var every = document.getElementById( "everywhere" ); //并将它从文档中移除 every.parentNode.removeChild( test ); }; </script> </body> </html>