JS DOM node type

Source: Internet
Author: User

The DOM (Document Object model) is an API for HTML and XML documents.

The DOM can portray any HTML or XML document as a tree structure consisting of a multi-level node, with a specific node as the root node. The nodes are divided into 12 different types, each representing different information and/or tags in the document. These types inherit from a base type.

Take the following example:

<HTML> <!--document element, a child node of a document node, is the outermost element of the document. There is only one document element per document. -    <Head>        <title>My article</title>    </Head>    <Body>        <P>Hello World</P>    </Body></HTML>

The document node is the root node of each document. All other elements in the document are contained within the document element.

1. Node type

All node types in JavaScript inherit from node type.

Each node has a NodeType property (Somenode.nodetype), the type of the surface node. There are 12 numeric constants defined in the node type, and any node type must be one of the following:

To understand the details of a node, you can use NodeName and nodevalue. For an element node, NodeName always holds the label name of the element, while the value of NodeValue is always null.

node Relationship :

Operation Node :

AppendChild (NewNode)--Adds a node to the end of the ChildNodes list, returning the new node. If the node passed into AppendChild () is already part of the document, the result is that the node is transferred from its original location to the new location.

InsertBefore (the node to be inserted as the node of the reference)-place the node in a specific position in the ChildNodes list, returning the inserted node. When a node is inserted, the inserted node becomes the previous sibling node (previoussibling) of the reference node.

ReplaceChild (node to be inserted, nodes to replace)--returns the node to be replaced and removes it from the document tree.

JS DOM node type

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.