JavaScript12 Line code get related node

Source: Internet
Author: User

<!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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.