Dom is the document.
Compatibility conditions
-ie6~8 10%
-chrome 60%
-ff 99%
DOM node
Child nodes
-childnodes contains text nodes and ELEMENT nodes//ie6-8
ABCDE text node <SPAN>ABCD element node </span>
-nodetype return node type
NodeType = = 3 Text node
NodeType = = 1 element node
<script>function() { var oul=document.getelementbyid (' ul1 '); for (var i=0;i<ali.length;i++) { if(oul.childnodes[i].nodestype = = 1) { = ' red ';}} } </script><body><ul id= "UL1" > <li></li> <li></li></ul> </body>
-children includes only elements, not text
Parent node
-parentnode
<script>window.onload=function(){ varAa=document.getelementsbytagnaame (' a '); for(vari=0;i<aa.length;i++) {Aa[i].onclick=function(){ This. ParentNode.style.display = ' None '; } }}</script><body><ul> <li>111<a href= "JavaScript" > Hide </a></li> <li> 222<a href= "JavaScript" > Hide </a></li> <li>333<a href= "JavaScript" > Hide </a></li > <li>444<a href= "javascript" > Hide </a></li> <li>555<a href= "JavaScript" > Hidden </a></li></ul></body>
-offsetperent get the actual position of the element on the page
-firstchild Gets the first child node//ie6-8
-firstelementchild//chrome, FF
Compatibility issue Resolution
<script>function() { var oul = document.getElementById (' ul1 '); if (oul.firstelementchild) { = ' red '; } Else (oul.firstchild) { = ' red '; }} </script><body><ul id = "UL1" > <li></li> <li></li> < li></li> <li></li> <li></li><ul></body>
Element Property Manipulation
-getattribute (name) get
-setattribute (name, value) settings
-removeattribue (name) Delete
Get elements with classname
<script>functionGetbyclass (oparent,sclass) {varAele = Oparent.getelementsbytagname (' * ')); varAresult = []; for(vari=0;i<aele.length;i++){ if(Aele[i].classname = =Sclass) {Aresult.push (aele[i]); } } returnAresult;} Window.onload=function(){ varOul = document.getElementById (' ul1 ')); varAbox = Getbyclass (Oul, ' box '); for(vari=0;i<abox.length;i++) {Abox[i].style.background= ' Red '; }}</script>[JavaScript] Dom Basics