This method is used to make a copy of matched elements. Using this method we can also makes a copies of their child nodes, texts, and attributes. In another words it makes the duplicate of the matched elements. Syntax :
$(selector).clone(true|false)
Parmeters : True : It specifiy if event handlers should be copied. Fasle :It specify if event handlers should not be copied Example : HTML Code :
<html>
<head></head>
<body>
<p>Hello Mukesh Tomar</p>
<button>Click to make copies of p tag content and add in the body elements</button>
</body>
</html>
jQuery Code :
$(document).ready(function(){
$("button").click(function(){
$("p").clone().appendTo("body") // make copy of p tag elements and append to body elements
});
});
Output :
Hello Mukesh Tomar
Hello Mukesh Tomar // whenever you click on above button, it will make a new copy of that p tag elements
0 Comment(s)