Htmldom node operations (get/modify/add or delete) _ javascript skills
Source: Internet
Author: User
DOM is a standard for getting, modifying, adding, or deleting HTML elements. The following describes how to operate htmldom nodes, for more information about how to obtain, modify, add, or delete HTML elements, see html dom. In html dom, everything is a node. DOM is the HTML of the node tree.
According to W3C html dom standards, all content in HTML documents is node:
The entire document is a document Node
Each HTML element is an element node.
The text in the HTML element is a text node.
Each HTML attribute is an attribute node.
Annotation is a comment node.
Html dom treats HTML documents as a tree structure. This structure is called a node tree:
Html dom Tree instance
Http://www.w3school.com.cn/ I /ct_htmltree.gif
With html dom, all nodes in the tree can be accessed through JavaScript. All HTML elements (nodes) can be modified or created or deleted.
All HTML elements are defined as objects, while programming interfaces are object methods and object attributes.
I. method for getting element nodes:
1. var node = document. getElementById ("nodeId ");
2. var nodelist = document. getElementsByClassName ("nodeclassname ");
3. var nodelist = document. getElementsByTagName ("nodetagname ");
2. operations that can be performed on an element node: 1. operations on the element node. 2. subnode operations. 3. Operations on sibling nodes. 4. operations on the parent node
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.