How to set Add / Remove in all text field identifiers Auto increment (ItemCode, ItemName Add to +1 and Delete to -1.)

<div id="mainDiv"> <div class="one"> <div class="row"> <div class="input-field col s1"> <input type="text" id="sno" class="sno" name="Sr[]" value="1" > <label for="Sr" >Sr</label> </div> <div class="input-field col s2"> <input id="ItemCode" type="text" name="ItemCode[]" onKeyUp="showHint(this.value)"> <label for="ItemCode" >Item Code</label> </div> <div class="input-field col s2"> <input id="ItemName" type="text" name="ItemName[]" value=" "> <label for="ItemName" >Item Name</label> </div> <div class="input-field col s1 add"> <a href="#">Add</a> </div> <div class="input-field col s1 delete"> <a href="#">Remove</a> </div> </div> </div> </div> $(document).ready(function () { $(".add").click(function () { var length = $('.one').length; var cloned = $(this).closest('.one').clone(true); cloned.appendTo("#mainDiv").find('.sno').val(length + 1); cloned.find(':input:not(".sno")').val(" "); var parent = $(this).closest('.one'); }); $('.delete').click(function () { if($('.one').length==1){ alert("This is default row and can't deleted"); return false; } var parent = $(this).closest('.one'); $(this).parents(".one").remove();
https://jsfiddle.net/Nilesh_Patel/05e3wtcm/1/ here is an example
source share