Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to use jQuery clone () Method ?
The clone () Method is used for making a copy of matched element.This Method makes the
duplicate of the matched elements.
clone () Method also makes a copies of their child nodes, texts, and attributes.
syntax of clone () Method
$(selector).clone(true|false)
There are two main parameter of above given syntax
1-True:-It specify if event handlers should be copied.
2-False:-It specify if event handlers should not be copied.
you can take reference of below example:
<html>
<head>
<!-- here define jquery library file -->
<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") // make copy of p tag elements and append to body elements
});
});
</script>
</head>
<body>
<!-- define a paragraf -->
<p>Hi joe ! How are you ?</p>
<button>Click to copy</button>
</body>
</html
The output of the code above will be:
Hi joe ! How are you ?
0 Comment(s)