jQuery clone()

The jQuery clone() method is used to duplicate elements on a page, to make copies of the selected elements.

Syntax:

$(selector).clone(true)  
$(selector).clone(false)

True: True parameter is used to specify that the event handler should also be copied.

False: False parameter is the default parameter of clone() method which specify that the event handler should not be copied.

Example 1

<!DOCTYPE html>
<html>
<!DOCTYPE html>
<html>
<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
$("button").click(function(){  
$("p").clone().appendTo("body");
});  
});  
</script>  
</head>  
<body>  
<button>Click me</button>  
<p>Hello! </p>  
</body>  
</html>

try it

JS Bin on jsbin.com

Example 2

<!DOCTYPE html>
<html>
<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
$("button").click(function(){  
$("#div1").clone().appendTo("body");
$("#div2").clone().appendTo("body");
$("#div3").clone().appendTo("body");
 
});  
});  
</script>  
</head>  
<body>  
<button>Click me</button>  
 
<div id="div1" style="width:40px;height:80px;background-color:red;border-radius:20px"></div><br>
<div id="div2" style="width:40px;height:80px;background-color:yellow;border-radius:20px;"></div><br>
<div id="div3" style="width:40px;height:80px;background-color:green;border-radius:20px"></div>
 
</body>  
</html>

try it

JS Bin on jsbin.com

Please Share