Home > Web Front-end > JS Tutorial > A brief analysis of some common methods of JS operating DOM

A brief analysis of some common methods of JS operating DOM

高洛峰
Release: 2017-02-06 09:34:54
Original
1285 people have browsed it

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");
Copy after login

setAttribute(): Adds the specified attribute and assigns it the specified value.

document.getElementsByTagName("INPUT")[0].setAttribute("type","button");
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template