How to clone an element using jQuery
In this article, we will explain to you how to clone an element using jQuery. so we will give you a simple example of how to clone an element using jQuery.
Example: jQuery clone() method
In this example, we use the jQuery clone() method to copy all elements and paste that into the specific element. so you can follow the below example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").clone().appendTo(".color"); }); }); </script> </head> <body> <p>red</p> <p>white</p> <div class="color"></div> <button>Clone all colors, and append to all colors in specific element</button> </body> </html> |
Please follow and like us: