clone()

The jQuery clone() method is used to make copies of the set of matched elements. It also makes copies of their child nodes, texts and attributes. The clone() method is a convenient way to duplicate elements on a page.

Syntax:

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

Parameters of jQuery clone() method

Parameter Description
True It specifies that event handlers also should be copied.
False It is a default parameter. It specifies that event handler should not be copied.

Example of jQuery clone() method

Let's take an example to demonstrate the effect of jQuery clone() method.

snippet
<!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>
<p><b> javatpoint.com is a popular tutorial website.</b></p>
<p><b>javatpoint.com is a training institute also.</b></p>
<button>Click here, to clone all p elements, and append them to the body element</button>
</body>
</html>
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents