<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title></title></Head><Body><DivID= "DV"> <span>This is the first span tag in a DIV</span> <P>This is the second element in the Div, the first p tag</P> <ulID= "UU"> <Li>Qiao</Li> <Li>Velvet</Li> <LiID= "three">"Duan Yu</Li> <Li>Kakashi</Li> <Li>Waseda</Li> </ul></Div><Scriptsrc= "Common.js"></Script><Script> //12 lines of code, all of which get nodes and elements //ul varUlobj=document.getElementById ("UU"); //Parent-NodeConsole.log (Ulobj.parentnode); //Parent ElementConsole.log (Ulobj.parentelement ()); //child NodesConsole.log (ulobj.childnodes); //child elementsConsole.log (Ulobj.children); Console.log ("==================="); //first child nodeConsole.log (Ulobj.firstchild); //First child elementConsole.log (Ulobj.firstelementchild); //Last child nodeConsole.log (Ulobj.lastchild); //Last child elementConsole.log (Ulobj.lastelementchild); //the previous sibling node of an elementConsole.log (my$ ("three"). Previousnode ()); //the previous sibling element of an elementConsole.log (my$ ("three"). previouselementsibling); //the next sibling node of an elementConsole.log (my$ ("three"). NextNode ()); //the next sibling element of an elementConsole.log (my$ ("three"). nextelementsibling); /** Summary: All the code to get the node in Google and Firefox are ====== related nodes * All the code to get the elements in Google and Firefox are ===== related elements * from the "=======" back (from the child node and the sibling node) in general to obtain the code of the node in IE 8 is the element, * get the relevant code of the element, in the IE8 is the code of the undefined------element, not supported in IE8 **/</Script></Body></HTML>
JavaScript12 Line code get related node