Home > Web Front-end > JS Tutorial > body text

javascript copy node cloneNode() usage introduction_javascript skills

WBOY
Release: 2016-05-16 16:53:27
Original
1667 people have browsed it

The cloneNode(a) method accepts a Boolean parameter, indicating whether to perform a deep copy.
true: Indicates performing a deep copy, copying this node and the entire child node tree.
false: Shallow copy. Only the node itself is copied.
The node copy returned after copying belongs to the document, but does not have a parent node. Unless you use appendChild, insertChild(), replaceChild() to add it to the document

Copy code The code is as follows:


1
2< ;/span>
3

var oDiv = document.getElementById("guoDiv");
var deepList = oDiv.cloneNode(true ); //Copy child nodes
alert(deepList.childNodes.length); //3 or 7 (compatibility issue, so the results are different)
var showList = oDiv.cloneNode(false); //Only Copy the reference of the current element
alert(showList.childNodes.length); //0
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