JS FirstChild, NextSibling, LastChild, previoussibling, parentnode

Source: Internet
Author: User

NextSibling Next Sibling node

PreviousSibling Last Brother

ParentNode Father Node

1<select><option value= "Zs" > Zhongshan </option><option value= "GZ" > Guangzhou </option><option Value= "zh" > Shenzhen </option><option value= "zh" > Zhuhai </option></select>2<script type= "Text/javascript" >3               //gets the number of child elements under the <select> element node4               //var selectelement = document.getElementsByTagName ("select") [0];5               //var size = selectElement.childNodes.length;6               //alert ("+size+" is a common element in "select");7               8               //get the "Zhongshan" string9               //var selectelement = document.getElementsByTagName ("select") [0];Ten               //var zselement = selectelement.firstchild; One               //var zs = zselement.innerhtml; A               //alert (ZS); -                -               //get the "Guangzhou" string the               //var selectelement = document.getElementsByTagName ("select") [0]; -               //var zselement = selectelement.firstchild; -               //var gzelement = zselement.nextsibling; -               //var gz = gzelement.innerhtml; +               //alert (GZ); -                +               //get the "Zhuhai" string A               //var selectelement = document.getElementsByTagName ("select") [0]; at               //var zhelement = selectelement.lastchild; -               //var zh = zhelement.innerhtml; -               //alert (zh); -                -               //get the "Shenzhen" string -               //var selectelement = document.getElementsByTagName ("select") [0]; in               //var zhelement = selectelement.lastchild; -               //var szelement = zhelement.previoussibling; to               //var sz = szelement.innerhtml; +               //alert (SZ); -                the               //Delete "Guangzhou" element *               varGzelement = document.getelementsbytagname ("option") [1]; $               varSelectElement =Gzelement.parentnode;Panax Notoginseng Selectelement.removechild (gzelement); -                the                +                A                the</script>

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.