I want to limit my multiple input to three inputs only. I tried if else but the value of I can't read also try creating another variable. I try also length but don't know how to use it.
$("#add-btn").click(function() {
i++;
$("#dynamicAddRemove").append('<tr><td><select name="moreFields[+i+][license_type]" class="form-control" required=""><option value="Psychometrician">Psychometrician</option><option value="Psychologist">Psychologist</option><option value="Teacher">Teacher</option><option value="Guidance Counselor">Guidance Counselor</option><option value="Medical Practioner">Medical Practioner</option><option value="Others">Others</option><option value="N/A">N/A</option></select></td> <td><input type="number" name="moreFields[+i+][license_number]" class="form-control" required></td><td><input type="date" name="moreFields[+i+][registration_date]" class="form-control" required></td><td><input type="date" name="moreFields[+i+][expiration_date]" class="form-control" required></td><td><button type="button" class="btn btn-danger remove-tr">-</button></td></tr>');
});
$(document).on('click', '.remove-tr', function() {
$(this).parents('tr').remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-12 pt-4 pb-1">
<span class="title fs-4 fw-bold">License</span>
<hr>
</div>
<table class="table" id="dynamicAddRemove">
<tr class="license">
<td>
<label>License Type </label>
<select name="moreFields[0][license_type]" class="form-control" required="">
<option value="Psychometrician">Psychometrician</option>
<option value="Psychologist">Psychologist</option>
<option value="Teacher">Teacher</option>
<option value="Guidance Counselor">Guidance Counselor</option>
<option value="Medical Practioner">Medical Practioner</option>
<option value="Others">Others</option>
<option value="N/A">N/A</option>
</select>
</td>
<td>
<label>License Number</label>
<input type="number" name="moreFields[0][license_number]" class="form-control" required>
</td>
<td>
<label>Registration Date</label>
<input type="date" name="moreFields[0][registration_date]" class="form-control" required>
</td>
<td>
<label>Expiration Date</label>
<input type="date" name="moreFields[0][expiration_date]" class="form-control" required>
</td>
<td><button type="button" name="add" id="add-btn" class="mt-4 btn btn-primary rounded-pill" onclick="incrementClick()">+</button></td>
</tr>
</table>
document.getElementsByTagName("input").lengthto check for the current number of inputsi++;and from#add-buttontheonclick="incrementClick()"attribute.