Due to the introduction of the DOM (Document Object Model), this API makes HTML, such as tiger, but some friends who have learned DHTML are still some flexing, just because the current manual is not scientifically, it is in the letter, it is inconvenient to consult. The most important thing in the DOM is to master the relationship between nodes and nodes. If you want to learn DOM in DHTML, don't look through all properties and methods from head to tail, you have three countries when Zhang Song. " Do you not forget the skills? Nothing, then listen to me analysis:
In fact, DOM teaches us is a hierarchy, you can understand as a tree structure, just like our directory, an root directory, a subdirectory in the root directory, and a subdirectory in the subdirectory ...
Root node:
DOM calls every object in the hierarchy (Node), taking an HTML hypertext tag language: One root of the entire document is , you can use DOCUMENT.DOCUMENTELE in the DOM to access it, it is The root node of the entire node tree (root)
Child node:
Nodes in the general sense, the maximum child node below the root node is the main documentation area
, to access the Body tab, write in the script:Document.body
All text and HTML tags within the Body area are nodes of documents, known as text nodes, element nodes (or label nodes), you know that HTML said that it is only text, no matter how much, the web is inevitable from these two The node consists, and it can only be composed of these two nodes.
The relationship between nodes:
The relationship between nodes is also the most important joint in the DOM. How to correctly reference node objects, be sure to know the mutual description of each node of the node tree, in DHTML, JavaScript script uses a set of various node objects And attributes describe additional node objects.
Absolute reference for nodes:
Return to the root node of the document
Document.documentelement
Returns the label node that is hitted in the current document
Document.ActiveElement
Returns the source node that moves out of the mouse
Event.Fromelement
Return to the source node moved in the mouse
Event.toelement
Returns the source node of the activation event
Event.srcelement
Relative references for nodes: (set the current node node)
Return to the parent node
Node.ParentNode
Node.parentelement
Return sub-node collection (including text nodes and tag nodes)
Node.childNodes
Return sublarm node collection
Node.Children
Return sub-text node collection
Node.TextNodes
Returns the first child node
Node.FirstChild
Returns the last child node
Node.lastchild
Returns the next node
Node.nextsibling
Returns the same node
Node.PRevioussibling
Various operations of the node: (set the current node is node)
Added label node handle:
Document.createElement (Snode) // Parameter is the node tag name to which you want to add, an example: newNode = document.createElement ("DIV");
1, add nodes:
Additional child nodes:
Node.Appendchild (onode) // onode is a new node handle, an example: node.appendchild (newNode)
Apply label node
Node.ApplyLMent (onode, swhere) // onode is a new node handle, Swhere has two values: Outside / Inside, adding outside the current node or inserting nodes
Inode.insertbefore ()
Node.insertAdjacentelement ()
node.replaceadjacenttext ()
2, modify the node:
Delete node
Node.remove ()
Node.removechild ()
node.removenode ()
Replacement node
node.replacechild ()
Node.Replacenode ()
node.swapnode ()
2, copy the node:
Return to copy replication node reference
Node.clonEnode (ball) // Ball is the Boolean value, whether the True / False clone the node all child nodes
3, node information
Whether to include a node
node.contains ()
Whether there is a child node
node.haschildnodes ()