What are the use if clone method in JQuery?

Asked 28-Jul-2021
Viewed 194 times

1 Answer


2

 We are generally use the copy of data, from any specific work. In this JQuery has clone () method for making duplicate data of selected elements. We are append this duplicate data in html page. It also makes copies of their child nodes, texts and attributes.
Syntax
 $(selector).clone ( true| false )
Example 

<!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').css({'background-color':'orange','color':'white'});
    });
});
</script>
</head>
<body>
<p>MindStck pvt ltd in allahabad </p>
<button>Click me to clone data and add in html page</button>
</body>
</html>
Output
What are the use if clone method in JQuery?