DOM, the Document Object model: A part of JavaScript, provides programmatic interfaces for accessing and modifying HTML documents or XML documents, and the DOM describes the contents of the document as objects and manages them in a tree-shaped structure. and provides some ways to get these objects and modify them.
Get Object method:
1.document.getelementbyid (): Returns a reference to the first object that owns the specified ID.
2.document.getelementsbyname (): Returns a collection of objects with the specified name.
3.document.getelementsbytagname (): Returns a collection of objects with the specified label name.
The above three methods are often used to get the element object of the method, the DOM is composed of nodes, and all the nodes need to get the element object after the DOM provided by the specific method obtained, so these methods are used in the DOM programming portal, in the DOM each thing is a node:
- The document itself is a Document object
- All HTML elements are element nodes
- All HTML attributes are attribute nodes
- Inserting text into HTML elements is a text node
- Comment is a comment node
Get Node Method:
1.element.getattributenode (): Gets the node's attribute node.
2.element. FirstChild: Gets the first child node of the node.
3.element.lastchild: Gets the last child node of the node.
3.element.parentnode (): Gets the parent node of the node.
4.element.childnodes (): Returns an array of child nodes of the node (since spaces are also returned as text nodes.) So this method is often used Element.getelementsbytagname () instead).
5.element.nextsibling: Returns the next sibling node of the node. 6.element.previoussibling: Returns the previous sibling node of the node.
Node Common properties:
1.element.nodename: The content is the name of the given node. If it is an element node, NodeName returns the name of the element (the label signature). If it is an attribute node, NodeName returns the name of the property (property name). If it is a text node, NodeName returns a string with a content of #text. 2.element.nodetype: Returns an integer that represents the type of the given node. node.element_node ---1 --element node node.attribute_node ---2 --Attribute node node.text_node ---3 & nbsp; --Text node 3.element.nodevalue: Returns the current value (string) of the given node. If the given node is an attribute node, the return value is the value of this property. If the given node is a text node, the return value is the content of the text node. If the given node is an element node, the return value is null. Common methods for Operation nodes: 1.element.appendchild (): Joins a child node at the end of all child nodes of the node. 2.element.insertbefore (New,old): Joins a child node before the specified child node of the node. 3.element.removechild (): Deletes the specified child node of the node. 4.element.replacechild (New,old): Replaces the node's specified child node. 5.element.clonenode (Boolean): copies the specified node and returns, when the parameter is true, copies the child nodes, which defaults to false. The innerHTML property is not a recommended standard, but because of its ease of operation, most mainstream browsers support this property, which makes it easy to get or write text information about an element, which can be called directly to get the text content of an element. You can also write the specified HTML text to an element that invokes the property by assigning a string.
Common methods for DOM summary