JSFiddle - React, Tailwind, and code Playground
HTML
<form id="theForm">
<div class="formDiv">
THING
<div class="innerContainer">
<input type="text" placeholder="Textbox"/>
<button class="innerBtn">Add new input</button>
</div>
</div>
<br>
<button id="deadlyBtn">I append to body, breaking the above button</button>
</form>
CSS
input{
display:block;
}
JavaScript
//.innerBtn is a class because there could be several copies generated
$("#theForm").on("click", ".formDiv .innerContainer .innerBtn", function(e){
e.preventDefault()
$(this).before($('<input type="text" placeholder="Textbox"/>'))
})
$("#deadlyBtn").click(function(e){
e.preventDefault()
$('body').append("Now try clicking [Add new Input]")
//document.body.innerHTML += "Now try clicking [Add new Input]"
})