getElementById(): Gets the elements in the document with the specified unique ID attribute value
getElementsByName(name): Returns an array
getElementsByTagName(): Returns the element with the specified tag name Child element collection
getAttribute(): Returns the attribute value of the specified attribute name
document.getElementsByTagName("a")[0].getAttribute("target");
setAttribute(): Adds the specified attribute and assigns it the specified value.
document.getElementsByTagName("INPUT")[0].setAttribute("type","button");
Node attributes:
Node name (read only):nodeName
Node value: nodeValue
Node type (only Read):nodeType
Child node:
ele.childNodes Return array
firstChild
lastChild
Parent node
parentNode has only one
sibling node
nextSibling The node immediately following a node
previousSibling
Insert node
appendChild( ) Insert at the end
insertBefore(newnode,node) before the node node
Remove node
removeChild(node) Successfully returns the deleted node. Failure returns null
Replace element node
replaceChild(newnode,oldnode) implements the replacement of child node objects
Create element node
createElement()
Create text Node
createTextNode()
Copy node
The node that needs to be copied.cloneNode(true/false)
true copies the current node and all child nodes , false only copies the current node
The above article briefly analyzes some common methods of JS operating DOM is all the content shared by the editor. I hope it can give you a reference, and I also hope you will support PHP Chinese website. .
For more related articles that briefly analyze some common methods of JS operating DOM, please pay attention to the PHP Chinese website!