I have a button that when clicked inserts a form input field and a button (to delete) into the form using JQuery .after(). This works fine.
The button that is inserted has a function .click that should run when it is clicked - it is not working.
<script type="text/javascript">
$("#addAQuestion").click(function(){
var begin = "<tr>";
var question = "<td><input type='text' name='question'/>";
var deleteButton = "<input type='button' class='deleteQuestion' name='delete' value='Del' /></td>";
var end = "</tr>";
$("#questions").after(begin + question + deleteButton + end);
});
$(".deleteQuestion").click(function(){
alert('test');
//$(this).parent().empty();
});
</script>
How come the alert is not being triggered when a user clicks on the .deleteQuestion button?
Thanks!