Nodelist

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 2 <html xmlns="http://www.w3.org/1999/xhtml">

 3 <head>

 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

 5     <title>test7</title>

 6 </head>

 7 <body>

 8     <div>old div</div>

 9     <script type="text/javascript" src="test7.js"></script>

10 </body>

11 </html>
1 var divs = document.getElementsByTagName("div");

2 

3 for (var i = 0, len = divs.length; i < len; i++) {

4     var div = document.createElement("div");

5     div.appendChild(document.createTextNode("new div"));

6     document.body.appendChild(div);

7 }

你可能感兴趣的:(list)