JSFiddle - React, Tailwind, and code Playground
HTML
<div id="parts">Part
<input type="text" id="auto_part" name="auto_part" />
<br/>Description
<input type="text" id="auto_description" name="auto_description"
/>
</div>
<a href="#" id="addField">Add another part</a>
JavaScript
$(function () {
var $scntDiv = $('#parts');
var i = $('#parts input').size();
$('#addField').on('click', function () {
var part = '<div id="parts' + i + '"><span>Part</span> <input type="text" id="auto_part' + i + '" name="auto_part' + i + '" /><br/>' +
'<span>Description</span> <input type="text" id="auto_description' + i + '" name="auto_description' + i + '" /> <br />' +
'<input type="hidden" id="row_count' + i + '" name="row_count' + i + '" value="" />' +
'<a href="#" class="removefield">Remove</a></div>';
$scntDiv.after(part);
i++;
return false;
});
$(document).on("click", ".removefield", function () {
if (i > 2) {
$(this).parent('div').remove();
i--;
}
return false;
});
});