I had guessed that this code would work. But the JS doesn't alert anything. What is the best way to run functions on replaced content? It is a simple code as you can see, if you work with jquery. I need answers only if you have suggestions.
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<button type="button" id="add" name="sub">Add</button>
<script>
$(document).on('click',"#add",function(){
$( this ).replaceWith("<button type='button' id='sub'> Alert </button>");
});
$(document).ready(function(){
$("#sub").click(function()
{
alert("Does it alert?");
});
});
</script>