<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>dom Object Learning </title> <script language=" javascript "type=" Text/javascript " > Function Searchnode () {/* text node////////////////////* Attribute node * ("Li"); Alert ("+nodes.length+" the first node element name "+nodes[0].tagname+"; The first node text "+nodes[3].childnodes[0].nodevalue" of node fourth); var nodes2=document.getelementsbytagname ("ul"); var subnodes=nodes2[1].getelementsbytagname ("Li"); Alert ("+subnodes.length+"; the name "+subnodes[0].tagname+" of the first node element; The first node text "+subnodes[0].childnodes[0] of the first node element." NodeValue); var Nodeid=document.getelementbyid ("LiNode"); Alert ("Node name" +nodeid.tagname+ "; 1th node's first node text" +nodeid.childnodes[0].nodevalue); Traversal element var Ulnodes=document.getelementbyid ("Ulnode"); var domstring= ""; if (Ulnodes.haschildnodes ()) {var subulnodes=ulnodes.childnodes; for (Var i=0;i<subulnodes.length;i++) {domstring=domstring+subulnodes[i].childnodes[0].nodevalue+ "\ n"; } alert (domstring); Node attribute var imgtitle=document.getelementsbytagname ("img") [0]; var titlestring=imgtitle.getattribute ("title"); var altstring=imgtitle.getattribute ("Alt"); Alert (titlestring+ "\ n" +altstring); var p=document.createelement ("P"); var Text=document.createtextnode ("This is the second node"); P.appendchild (text); Document.body.appendChild (P); The use of innerHTML var Inner=document.getelementbyid ("inner"); alert (inner.innerhtml); Inner.innerhtml= ""; } </script> </pead> <body onload= "Searchnode ()" > <ul id= "Ulnode" > <li>java</li> <li>javascript</li> <li>CSS</li> </ul> <ul> <li id= "LiNode" >ajax</li& Gt <li>c#</li> <li>c++</li> </ul> <p> This is the first node </p> <div id= "inner" >Use of <p>innerhtml </p></div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]