I have a form with multiple rows of dynamically added input fields,
I want to be able to remove the last row of these fields (provided it is not the only row)
I'm trying this as follows
The Javascript
$("#remove-item").click(function() {
if ($('.input-row:first') !== $('.input-row:last')) {
$('.input-row:last').remove();
}
});
The HTML (abridged for simplplicity)
<div class="input-row">
<input />
<input />
<input />
</div>
<div class="input-row">
<input />
<input />
<input />
</div>
I thought this would work as in case where there is only one line of <input>
fields I'm effectively selecting the same element twice by different selectors,.
In cases where the jQuery selectors match different elements, then there has to be more than one row so it should be okay to remove the last one.