jQuery clone()
method is used to create a deep copy of the set of matched elements. It copies the matched elements as well as all of their descendant elements and text nodes.
clone() Syntax:
$(selector).clone('true|false')
jQuery clone()
method is used to create a deep copy of the set of matched elements. It copies the matched elements as well as all of their descendant elements and text nodes.
clone() Syntax:
$(selector).clone('true|false')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery clone()</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#button").click(function() {
$("p").clone().appendTo("body");
});
});
</script>
</head>
<body>
<p>This is first paragraph. </p>
<button style="margin:0 0 10px 0" class="btn" id="button">Click here</button><br />
</body>
</html>