I am using a jquery clone.
When I click the add button, one clone is created with the above fields ... before that, the clone works fine
But when I double click the "Add" button, it creates three copies of the clone ... it creates three copies, etc.
I need when I create the add button, it just creates only one clone each time, and when I click the "Delete" button, it removes the last clown ...
below is my code.
<fieldset id="exercises">
<div class="exercise">
</div>
</fieldset>
<script>
$('#add_exercise').on('click', function() {
$("<div class='exercise address_box'><div class='box'></div></div>").appendTo('#exercises');
$("#toaddress").clone().val("").appendTo(".box");
$("#sender_name").clone().val("").appendTo(".box");
$("#OrderMobileCountryCode").clone().val("").appendTo(".box");
$("#sender_no").clone().val("").appendTo(".box");
$("#presentation").clone().val("").appendTo(".box");
$("<br><button type='button' class='orange_btn' id='add_exercise'>Remove</button>").appendTo('.box');
$("<br>").appendTo('.box');
$("<br>").appendTo('#exercises');
});
$('#exercises').on('click', '.orange_btn', function() {
$(this).closest(".exercise").remove();
});
</script>
source
share