Home  >  Article  >  Web Front-end  >  Use js to complete operations such as adding, deleting, modifying, and copying nodes_javascript skills

Use js to complete operations such as adding, deleting, modifying, and copying nodes_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:05:35966browse

Requirements: Complete the operation of adding, deleting, modifying and copying nodes

Methods and attributes used:
1. Get the parent node of a certain node
parentNode attribute
2. Get the parent node of a certain node Child node collection
childNodes attribute
3. Create a new node
createTextNode (node ​​text content) The method of the document object is not very compatible with some browsers
createElement (object) Methods of the document object, for example: document.createElement("a");
4. Add attributes and attribute values ​​to a node object
setAttribute(attribute, attribute value); For example: aNode.setAttribute("href" ,"http://www.baidu.com");
5. Replace the child node under a certain node
replaceChild (new node, atomic node);
6. Add a node to Under a node
appendChild (node ​​to be added)
7. Clone a node

cloneNode(). Passing no parameters is the same as passing the true parameter, which means cloning the node includes child nodes

Copy code The code is as follows:




node_CURD.html













这里是第二个区域


这里是第三个区域


这里是第四个区域



Add:


< hr />
Delete:




Change:


Clone:



Statement:
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