Dom Note (ii): node interface

Source: Internet
Author: User

all nodes are represented using the node interface, and there are many ways to get nodes, such as document.getElementsByTagName (), Document.getelementsbyname () Returns a NodeList object, and then gets the nodes within it.

The properties and amplification of the nodes are defined on the node interface:

1. List of attributes common to node interface

Property name Data type Description
NodeName Domstring Return to Node name
NodeValue Domstring Return node value
NodeType Int Return node type (see later)
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 child node of the current node
LastChild Node Returns the last child node of the current node
PreviousSibling Node Returns the immediate previous sibling node of the current node
NextSibling Node Returns the next sibling node immediately adjacent to the current node
Attributes NamedNodeMap Returns all properties 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 current node's qualified name

2. List of common methods for node interface

Method name Data type Description
AppendChild Node Add a child node at the end
CloneNode Node Cloning a child node
HasAttributes Boolean Determine if the node has attributes
HasChildNodes Boolean Determine if the node has child nodes
InsertBefore Node Inserts a node at the specified node
IsSupported Boolean Determine whether node-specific is supported
Normalize Void Normalize nodes
RemoveChild Node Delete a child node
ReplaceChild Node Replace a child node

3. Node Type

In a DOM document, each node belongs to a type, and you can use the Node.nodetype property to get the type of the node. The DOM specification specifies 12 types of nodes that can be represented by constants defined by the node interface, or by numbers.

Node Type constants 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 instruction Nodes
Comment_node 8 Comment Node
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, preferably in numerical notation. Six most common types of node: 1,2,3,8,9,11

Original starting:http://www.ido321.com/1318.html

Next article: Dom Note (iii): element interface and HtmlElement interface

Dom Note (ii): node 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.