JavaScript cloneNode(): clone node

Syntax:
nodeObject.cloneNode(boolean)
Parameter description:

QQ截图20161013113010.png

For example, clone the node with id="demo":

<div id="demo">
    <div>点击这里进行克隆</div>
    <div>节点</div>
    <div>节点</div>
</div>
<script type="text/javascript">
document.getElementById("demo").onclick=function(){
    alert(this.cloneNode(true).children.length);
}
</script>


Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<div id="demo">
<div></div>
<div></div>
<div></div>
</div>
<script type="text/javascript">
document.getElementById("demo").onclick=function(){
alert(this.cloneNode(true).children.length);
}
</script>
</head>
<body>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭