Menu Close

How to clone and remove an element using jQuery?

jQuery clone

To clone an element using jQuery, use the jQuery.clone() method. The clone() method clones matched DOM Elements and select the clones. This is useful for moving copies of the elements to another location in the DOM. 

Also jQuery.remove() method used to remove the elements.

        <title>jQuery clone method</title>
        <script src = ""></script>
            $(document).ready(function() {
                $(".remove_btn").click(function(e) {

                $(".clone_btn").click(function() {
        <div class="copydiv">
                <label>Email ID</label>
                <input type="text" name="name" placeholder="Enter Name">
            <a href="#" class="remove_btn">Remove </a>
        <button class="clone_btn">Clone</button>
If you want to disable remove text from first input field add below style.
    .copydiv:first-child .remove_btn{
Posted in jQuery

You can also read...