I am trying to add question box as shown below, the first remove button works fine. But when I dynamically add the div and then try to remove it does not work. I tried to alert on deleting question it still does not work. Can anyone help me on this ?
JS
<script type="text/javascript">
jQuery(document).ready(function(e) {
jQuery( '#add-question' ).on('click', function() {
var lastId = jQuery('.del-question').last().data('id');
var nextId = lastId+1;
var questionBox = '<div class="question-box box-1"><h2>Question 1</h2><input type="text" name="ques_title" class="ques_title" placeholder="Enter question title" value=""><div class="form-group"><a class="del-question button" href="#" data-id="1">Remove</a></div></div>';
jQuery('.question-box').after(questionBox);
return false;
});
jQuery( '#quiz-box .del-question' ).on('click', function() {
var id = jQuery(this).data('id');
jQuery('.box-'+id).remove();
return false;
});
});
</script>
HTML
<div id="quiz-box">
<div class="question-box box-1">
<h2>Question 1</h2>
<input type="text" name="ques_title" class="ques_title" placeholder="Enter question title" value="">
<div class="form-group">
<a class="del-question button" href="#" data-id="1">Remove</a>
</div>
</div>
<div class="form-group">
<a id="add-question" class="button" href="#">Add</a>
</div>