How to Get dom using js

Source: Internet
Author: User

Interface NodeType constant NodeType Value Remarks
Element Node. ELEMENT_NODE 1 Element Node
Text Node. TEXT_NODE 3 Text Node
Document Node. DOCUMENT_NODE 9 Document
Comment Node. COMMENT_NODE 8 Annotated text
DocumentFragment Node. DOCUMENT_FRAGMENT_NODE 11 Document parts
Attr Node. ATTRIBUTE_NODE 2 Node attributes

Method Description
CreateAttribute () Create a new Attr node with the specified name.
CreateComment () Creates a Comment node with the specified string.
CreateElement () Create an Element node with the specified tag name.
CreateTextNode () Creates a TextNode with the specified text.
GetElementById () Return the Element node with the specified id attribute in the document.
GetElementsByTagName () Returns all Element nodes with the specified tag name in the document.

Attribute Description
Attributes If the node is an Element, the attribute of the Element is returned in the form of NamedNodeMap.
ChildNodes Store the subnodes of the current Node in the form of Node. If no child node exists, an empty array is returned.
FirstChild Return the first subnode of the current Node as a Node. If no subnode exists, the value is null.
LastChild Return the last subnode of the current Node as a Node. If no subnode exists, the value is null.
NextSibling Return the sibling Node of the current Node in the form of Node. If no such node exists, null is returned.Next sibling Node
NodeName The name of the node. The Element node represents the Tag Name of the Element.
NodeType Indicates the node type.
ParentNode ReturnsParent node. If no parent node exists, the value is null.
Previussibling Return the sibling Node next to the current Node and before it in the form of Node. If no such node exists, null is returned.Previous sibling Node

Method Description
AppendChild () Add a node to the childNodes [] Group of the current node to add a node to the document tree.
CloneNode () Copy the current node or all its child nodes.
HasChildNodes () If the current node has a subnode, true is returned.
InsertBefore () Insert a node to the document tree before the specified child node of the current node. If the node already exists, delete it and insert it to its location.
RemoveChild () Delete the child node from the document tree and return the specified child node.
ReplaceChild () Delete the child node from the document tree, return the specified child node, and replace it with another node.

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.