What are the use if clone method in JQuery?

0 votes
49 views
Ethan Karla asked 28-Jul-2021 in Web Application by Ethan Karla

What are the use if clone method in JQuery? 

1 Answer

1 votes
Ravi Vishwakarma answered 29-Jul-2021 by Ravi Vishwakarma
 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?