JSFiddle - React, Tailwind, and code Playground
HTML
<div class="participants">
<div class="participant">
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
<button class="remove-me">
Remove
</button>
</div>
</div>
<button id="add-participant">
Add Another
</button>
JavaScript
var pHTML = $(".participant")[0].outerHTML;
$("#add-participant").on("click", function() {
if($(".participant").length < 5) {
$(pHTML).appendTo(".participants");
}
});
$(".participants").on("click", ".remove-me", function() {
if($(".participant").length > 1) {
$(this).closest(".participant").remove();
} else {
$(".participants").html(pHTML);
}
})