DOM note (2): Node interface and dom note node interface

Source: Internet
Author: User

DOM note (2): Node interface and dom note node interface

All nodes are represented by the Node interface. You can use many methods to obtain nodes, such as document. getElementsByTagName (), document. getElementsByName () and so on all return a NodeList object, and then obtain the node.

The Node attributes and amplification are defined on the Node interface:

1. List of common Node interface attributes

Attribute name Data Type Description
NodeName DOMString Return node name
NodeValue DOMString Return node Value
NodeType Int Return node type (see the following section)
ParentNode Node Returns the parent node of the current node.
ChildNodes NodeList Returns all child nodes of the current node.
FirstChild Node Returns the first subnode of the current node.
LastChild Node Returns the last subnode of the current node.
Previussibling Node Returns the adjacent sibling node of the current node.
NextSibling Node Returns the next sibling node of the current node.
Attributes NamedNodeMap Returns all attributes of the current node.
OwnerDocument Document Returns the Document Object corresponding to the current node.
NamespaceURI DOMString Returns the URI Of The namespace to which the current node belongs.
Prefix DOMString Returns the prefix of the namespace to which the current node belongs.
LocalName DOMString Returns the local part of the specified name of the current node.

 

2. List of common methods of Node Interfaces

Method Name Data Type Description
AppendChild Node Add a subnode at the end
CloneNode Node Clone a subnode
HasAttributes Boolean Determines whether the node has attributes.
HasChildNodes Boolean Determine whether the node has subnodes
InsertBefore Node Insert a node into a specified Node
IsSupported Boolean Determine whether a node is supported
Normalize Void Normalized Node
RemoveChild Node Delete a subnode
ReplaceChild Node Replace a subnode

 

3. Node Type

In the DOM document, each Node belongs to a type. You can use the Node. nodeType attribute to obtain the Node type. The DOM specification specifies 12 Node types, which can be expressed by constants defined by the Node interface or by numbers.

Node type constant Numeric representation Description
ELEMENT_NODE 1 Element Node
ATTRIBUTE_NODE 2 Attribute node
TEXT_NODE 3 Text Node
CDATA_SECTION_NODE 4 CDATA Node
ENTITY_REFERENCE_NODE 5 Entity reference node
ENTITY_NODE 6 Entity Node
PROCESSING_INSTRUCTION_NODE 7 Processing Command Node
COMMENT_NODE 8 Comment nodes
DOCUMENT_NODE 9 Document Node
DOCUMENT_TYPE_NODE 10 Document Type Node
DOCUMENT_FRAGMENT_NODE 11 Document fragment Node
NOTATION_NODE 12 Symbol Node

 

PS: IE does not support constant representation. It is best to use numbers for representation. The six most common Node types: 1, 2, 3, 8, 9, 11

First: http://www.ido321.com/1318.html

Next article: DOM note (3): Element interface and HTMLElement Interface

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.