<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script> window.onload = function(){ var oUl = document.getElementById("ul1"); //ie6-8 // alert(oUl.childNodes.length);//2 其他浏览器高版本 为5 加上了文本节点 console.log(oUl.children.length);//2 只包括第一层下的标签节点 //找到oUl下面的li 标签节点 for(var i = 0 ;i <oUl.childNodes.length;i++) { if(oUl.childNodes[i].nodeType == 1) { oUl.childNodes[i].style.background ="red"; } } } </script> </head> <body> <ul id="ul1"> <li></li> <li></li> </ul> </body> </html>