Related properties of node in JavaScript

Source: Internet
Author: User

1,childnodes

The ChildNodes property returns an array that contains the entire child elements of the given element node.

Retrieves the first child node of a BODY element:

var body_element=document.getelementbytagname ("Body") [0];

The BODY element has several child elements

var body_element_length=body_element.lchildnodes.length;

2,notetype

Retrieving the type of a node

alert (Body_element.notetype);

There are 12 types of notetype, but only three are of practical value: element node (attribute value 1), Attribute node (property value 2), text node (property value 3)

3,nodevalue

If you want to change the value of a text node, use the NodeValue property to retrieve and set the value of the node: Node.nodevalue

For example, retrieving <p id= "description" > the text value inside the,<p> element of the NodeValue attribute is a null value, the text contained in the <p> element is another node, is the first child node of the <p> element

alert (Description.childnodes[0].nodevalue);

4,firstchild

Represents the first element of a childnodes[] array, childnodes[0] is equivalent to FirstChild

5,lastchild

Represents the last element of the childnodes[] array, lastchild equivalent to childnodes[node.childnodes.length-1]

Related properties of node in JavaScript

Related Article

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.