JSFiddle - React, Tailwind, and code Playground
by dirtyd77
HTML
<div id="firstdiv">
Pre Existing Div
<input type="button" id="adddiv" value="Add Div" />
</div>
JavaScript
$(document).ready(function () {
$('#adddiv').click(function () {
$('#firstdiv').append('<div id="seconddiv"> Click here to delete the second div: <input type="button" id="delete" value="Delete Div"><input type="button" id="delete2" value="Delete Div"></div>')
});
$('#firstdiv').on('click', '#delete, #delete2', function(e) {
$(this).parent('#seconddiv').remove();
});
});