Jquery Clone Example - Jquery

How to create a copy of element using jquery?

Snippet Code

Rate this page :
  [ 0 votes]

Simple jquery code allows you to create a copy of the matched elements. Here jquery clone() method is used to copy the div element and inserts after the prior one.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("div").click(function () { $(this).clone().insertAfter(this); }); }); </script> <style> .div{ margin:10px;padding:12px; border:2px solid #666; width:50px;cursor:pointer;} </style> <p>Click the below square :</p> <div class="div" style="background-color:green;">Demo</div>


Ask Questions

Ask Question