[Javascript] DOM summary, javascriptdom
The Document Object Model of DOM (Document ObjectModel) describes the number of hierarchical nodes. D (document) is a webpage document, O (object) is a window object, and so on. Its Attributes and methods can be called. M (model) is the tree structure of the webpage document. DOM defines the objects and attributes of HTML elements and the methods for accessing them. That is, DOM can obtain, modify, add, and delete HTML elements.
1. DOM Node
DOM treats tags as nodes and considers webpages as node trees composed of nodes. There are five types of nodes: document nodes, element nodes, text nodes, attribute nodes, annotations, and nodes. Each HTML element is an element node, the text in the HTML element is a text node, each HTML attribute is an attribute node, and the comment is a comment node, these concepts are easy to understand.
1) node attributes
DOM nodes have several useful attributes: nodeName, nodetype, and nodeValue.
The nodeName attribute specifies the node name, which always contains the uppercase letter Tag Name of the HTML element; the nodeValue attribute specifies the node value; The nodeType attribute returns the node type, and the nodeType is read-only.
2) Hierarchical node attributes
The hierarchy of nodes can be divided into Parent nodes, child nodes, and sibling nodes. When an element node is obtained, you can use the hierarchical node attribute to obtain other hierarchical nodes.
2. node methods for convenient operations, W3C provides some attributes and methods for locating nodes. You can create, search, and delete nodes using their DOM:
These methods make operations on Webpage elements more convenient.