I have 3 input fields with a button + Add more . I want to add more fields when the + Add more button is clicked .
When a new field is created, there must be a delete button to delete the newly added row, and a new row can be created using the + Add more button .
For this, I use the following html and jQuery code, but I can’t figure out how to add / remove fields!
html and jQuery code
<div id="tab_logic" class="after-add-more">
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Logger Name</label>
<input maxlength="200" type="text" class="form-control" placeholder="Enter Logger Name" name="lg_name[]" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Logger Serial Number</label>
<input maxlength="200" type="text" class="form-control" placeholder="Enter Serial Number" name="lg_sl[]" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Modem Serial Number</label>
<input maxlength="200" type="text" class="form-control" placeholder="Enter Modem Serial Number" name="lg_md_sl[]" />
</div>
</div>
<div class="remove-button"></div>
</div>
<div class="col-md-2">
<div class="form-group change">
<label for=""> </label><br/>
<a class="btn btn-success add-more">+ Add More</a>
</div>
</div>
<div class="more-feilds"></div>
$(document).ready(function() {
$(".add-more").click(function(){
var html = $("#tab_logic").html();
$(".more-feilds").append(html);
});
$("body").on("click",".remove",function(){
$(this).parents("#tab_logic").remove();
});
});
Update:
I updated the html and jquery code. Now I have a + Add more button. When I clicked the button, she added 3 new input fields that I want. But I want to add a delete button for each newly created 3 field to delete it.
How can i do this?