Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery clone() Method

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 368
    Comment on it

    The clone() method is used to make clone of the elements that are matching to the selected elements and select the clones.

    It basically makes copies of the selected DOM element to some other place in the DOM.

    Syntax:

    selector.clone()
    

    Example:

    <html>
    
       <head>
          <title>The jQuery clone method</title>
          <script type = "text/javascript" 
             src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function() {
                $(".one").click(function () {
                   $(this).clone().insertAfter(this);
                });
             });
          </script>
    
          <style>
             .one{margin:10px;padding:12px; border:2px solid #666; width:60px;}
          </style>
       </head>
    
       <body>
    
          <p>Click on any of the box:</p>
    
          <div class = "one" style = "background-color:blue;"></div>
          <div class = "one" style = "background-color:red;"></div>
          <div class = "one" style = "background-color:yellow;"></div>
    
       </body>
    
    </html>
    

    When we click on any of the div element having class one it will insert a copy of that element after this.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: