Im having problems trying to fire an event (alert) on my script. This is the html:
<div class="dynamic-form">
<form>
<div class="inputs"></div>
<a href="#" id="add">ADD</a>
<input name="submit" type="button" class="submit" value="Submit">
</form>
</div>
And the JS:
$(document).ready(function(){
var i = 1;
$('#add').click(function() {
$('<div id="d' + i + '" class="fielddiv"><input type="text" class="field" name="dynamic[]" value="' + i + '" /><a href="#" id="remove_question">Cancella</a><hr></div>').fadeIn('slow').appendTo('.inputs');
i++;
});
$('#remove_question').on("click", function(event) {
alert('dsfsfd');
//$('#d' + $this.attr('todel')).remove();
});
// here's our click function for when the forms submitted
$('.submit').click(function(){
var answers = [];
$.each($('.field'), function() {
answers.push($(this).val());
});
if(answers.length == 0) {
answers = "none";
}
alert(answers);
return false;
});
});
The remove question on click function should fire an alert but is not doing anything, not even an error, what am i doing wrong? Here is a jsfiddle too.