DOM的节点

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"        "http://www.w3.org/TR/html4/loose.dtd"><html><head>    <title>Title</title></head><body><!--DOM节点--><!--document object--><!--element object--><!--attribute object--><!--text object--><!--comment object--><div id="div1">    <div>hello star</div>    <p>hihi p</p></div><script>    var ele=document.getElementById(‘div1‘)//    alert(ele)//[object HTMLDivElement//    console.log(ele.nodeName);//DIV//    console.log(ele.nodeType);//1//    console.log(ele.nodeValue);//null//    var ele1=ele.firstChild;//    console.log(ele1.nodeName);//#text  ---- DIV//     var ele2=ele.lastChild;//    console.log(ele2.nodeName);//text----P//    var ele3=ele.childNodes;//    console.log(ele3.length);//5     var ele3=ele.parentNode;    console.log(ele3.nodeName);//BODY</script></body></html>

相关推荐