实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div></div> <ul id="uls"> <li>1</li> <li>2</li> <!-- 今天天气挺好的!!! --> <li id="demo">3</li> <li>4</li> <li>5</li> </ul> </body> <script> //alert(document.documentElement.nodeName); //alert(document.body.nodeName); //测试元素节点 var uls = document.getElementById('uls'); //alert(uls.nodeName); //alert(uls.firstChild.nodeName); //alert(uls.lastChild.nodeName); //console.log(uls.childNodes); console.log(uls.children[0]); </script> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例