JavaScript series (ii) DOM

Source: Internet
Author: User

The DOM (Document Object model) depicts a hierarchical tree of nodes.

1.1 Node type

The node type can be divided into 12 types, all of which inherit from node type and share the same basic properties and methods. The main node types are the element node, the attribute node (attribute node), and the text node. To understand the details of a node, you can use NodeName and nodevalue two properties, and NodeType can determine the type of the node.

Where the element node NodeType is 1, the attribute node NodeType is 2, and the text node NodeType is 3.

if (Somenode.nodetype = = node.element_node) {       alert (' This is an element node ');}
Because of the particularity of IE, so the above code will appear error, in order to ensure the compatibility of the browser, so it is best to use the following method to determine its node type. if (somenode.nodetype = = 1) { alert (' This is an element node ');}

In each node, it has a childnodes property that holds the NodeList object ( Note: NodeList can automatically reflect changes in the DOM structure, which is dynamic.) ). Similarly, each node has a ParentNode property that points to the parent node of the text. All lists in the childnodes of a node have the same parent node. So in a node, there are several ways to manipulate nodes, represented by a graph.

Note:firstelementchild, nextelementsibling,

JavaScript series (ii) DOM

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.