Public properties and methods in the core DOM
Public properties and methods in the core DOM
Note: Searching for nodes (markers) in the core DOM starts from the root node of (html node).
##Node access
- nodeName: Node name.
- nodeValue: The value of the node. Only text nodes have values, element nodes have no values. The value of nodeValue can only be "plain text" and cannot contain any HTML tags or CSS attributes.
- firstChild: The 1st child node.
- lastChild: the last child node.
- childNodes: A list of child nodes, which is an array.
- parentNode: parent node.
Methods to find tags
-
##document.firstChild
- document.firstChild.lastChild
- document.body
##Attribute operations on nodes
- getAttribute(name): Get the value of a node attribute.
- removeAttribute(name): Delete the attribute of a node.
php.cn
Creation of nodes
- Example: var imgObj = document.createElement("img")
- ##parentNode.appendChild(childNode): Append the created node to a parent node.
- parentNode represents the parent node, and the parent node must exist.
childNode represents the child node.
- Example: document.body.appendChild(imgObj)
parentNode.removeChild(childNode): Delete a certain Child nodes under the parent node.
- #parentNode represents the parent node.
childNode represents the child node to be deleted.
Example: document.body.removeChild(imgObj)
php.cn