I have a form that allows a user to add or remove input fields but they can only add a specific number (5), once that number is hit the "Add Row" button is hidden. There is also a remove row button that will remove a row but I am having trouble getting the button to show again if the amount of rows falls back under 5. The number of allowed rows will be added dynamically so that will change on different pages. I have a fiddle set up (https://jsfiddle.net/keygrip/hkqmp8zf/6/) and here is my code for the add/remove feature:
$('.add-row').click(function(){
var sum = $('div.item').length;
if(sum >= 5){
$(this).hide();
}
});
$('.remove-row').click(function(){
var sum = $('div.item').length - 1;
if(sum <= 4){
$('.add-row').show();
}
});
Any help is appreciated.