JavaScript gets related nodes

Source: Internet
Author: User
Tags tag name

<!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>    varUlobj=my$ ("UU"); //parent node of the UL tagConsole.log (Ulobj.parentnode); //the parent element of the UL tagConsole.log (ulobj.parentelement); varDivobj=my$ ("DV"); //child nodes of DivConsole.log (divobj.childnodes); //child elements of a divConsole.log (Divobj.children); //Div    varDvobj=document.getElementById ("DV"); //get each child node inside     for (varI= 0; I<dvObj.childNodes.length; I++) {        varnode=Dvobj.childnodes[i]; //NodeType:---> Node type: 1---label, 2---property, 3---text        //nodeName:---> Node name: UPPERCASE Tag name----label, lowercase property name---property, #text---text        //nodevalue:---> Node value: Label---null, Property---property value, Text---text contentConsole.log (Node.nodetype+ "======" +Node.nodename+ "======" +node.nodevalue)}//Div    varDv1obj=document.getElementById ("DV"); //Gets the node of the attribute    varNode1=Dv1obj.getattributenode ("ID"); Console.log (Node1.nodetype+ "======" +Node1.nodename+ "======" +node1.nodevalue);</Script></Body></HTML>

JavaScript gets related nodes

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.