My page has a button and when it is clicked it is to create another button on that page which will trigger an alert box when clicked. Although, it seems as if the DOM is ignoring the on click event. Can someone shed some light? Thanks.
<div class="myDiv"></div>
Click Me!
$("#btnSub").on("click", function(){
$('<p>This will append to myDiv</p><br><button id="btnAfter">After button</button>').appendTo(".myDiv");
$('#btnSub').remove();
});
$("#btnAfter").on('click', function(){
alert("test");
});
JSFiddle : http://jsfiddle.net/jpavlov/fbojv76t/