Home >>jQuery Tutorial >jQuery clone() Method

jQuery clone() Method

jQuery clone() Method

jQuery clone() method in jQuery is used to makes a copy of selected elements, including text, child nodes and attributes.

Syntax:
$(selector).clone(true|false)

Parameter Values

Parameter Description
true It is used to specifies that event handlers also should be copied
false It is Default value and is used to Specifies that event handlers should not be copied
Here is an Example of jQuery clone() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".txt1").clone().appendTo("body");
});
});
</script>
</head>
<body>
<p class="txt1">This is a PHPTPOINT</p>
<p class="txt1">welcome to my world.</p>
<button class="btn1">click me to see effect</button>
</body>
</html>

Output:

This is a PHPTPOINT

welcome to my world.


No Sidebar ads