Basic Concepts
The DOM is the Document Object model for HTML and XML document APIs (application interfaces). It depicts a hierarchical node tree that runs a developer to add, remove, and modify portions of a page. Dom can access and modify the content and structure of a document in a platform-and language-independent manner, which is a common method of representing and processing an HTML or XML document.
D is document , the internet looked up its English translation, the original meaning is record. So it is a document that can be traced. o that is, object, which can be understood as something like a Window object, can invoke properties and methods. M (model) can be understood as the tree structure of a Web page document. Here, we should think about the nodes and some of the properties of the nodes. After all, we have learned the data structure, but also different from the data structure, where the node is a tag node, the types of nodes have element nodes, text nodes and attribute nodes.
Find Element
The DOM defines the standard for accessing HTML and XML documents, elements are an important part of HTML and XML, so finding elements is also an important part of the DOM.
getElementById () |
Accept a parameter: Gets the ID of the element. |
getElementsByTagName () |
Get a list of nodes of the same element |
Getelementsbyname () |
Get a list of nodes of the same name |
GetAttribute () |
Gets the value of a specific element node property |
SetAttribute () |
Set the value of a specific element node property |
RemoveAttribute () |
Remove specific Element node properties |
DOM node
Nodes can be divided into element nodes, attribute nodes, and text nodes, and these nodes have three very useful properties: NodeName, Nodetyoe, and NodeValue. and the data structure of the tree, Dom node also has a hierarchy, divided into: parent node and child node, sibling node two. When we get one of the element nodes, we can use the Hierarchy node property to get the nodes of its related hierarchy.
Property |
Description |
ChildNodes |
Gets all child nodes of the current element node |
FirstChild |
Gets the first child node of the current element node |
LastChild |
Gets the last child node of the current element node |
Ownerdocument |
Gets the document root node of the node, fairly |
ParentNode |
Gets the parent node of the current node |
PreviousSibling |
Gets the previous sibling node of the current node |
NextSibling |
Gets the next sibling node of the current node |
Attributes |
Gets all the attribute node collections of the current element node |
Dom can not only find nodes, but also create nodes, copy nodes, insert nodes, delete nodes, and replace nodes.
Method |
Description |
Write () |
This method can insert any string into the document. |
CreateElement () |
Create a node of an element |
AppendChild () |
Append a new node to the end of the list of child nodes |
createTextNode () |
Create a file node |
InsertBefore () |
Insert new node in front |
ReplaceChild () |
Replace the new node with the old node |
CloneNode |
Replication nodes |
RemoveChild () |
removing nodes |
Summary
The DOM Foundation is the basis for continuing learning below, and it will be more helpful to learn from the basics by mastering the underlying understanding. For a long time without learning it, should accelerate the pace of learning it as soon as possible into the next part of the content.
Basic JavaScript Basics--dom