I have a row in a div with a button at the end, when I click on the button it logs in the console.
I add another row via jquery with the same class but when I click on the button on the second row the event does not fire.
See the example here https://jsfiddle.net/DTcHh/24037/
Click add (to add second row) then on 'X' for each row (whilst monitoring console). Only row 1 works for me
code also below: HTML
<div id="tasksTableDiv">
<div class="row" id="1">
<div id="description_1"
class="col-sm-2 taskDescriptionCol">Description 1
</div>
<div class="col-sm-1 removeTaskCol">
<input id="button_1" class="removeTaskButton" type="button" value="X">
</div>
</div>
</div>
<button id="addTaskButton" type="button"
class="btn btn-sm btn-primary">Add Task</button>
JS
$('.removeTaskCol').on('click', function(){
console.log("Clicked X");
});
$('#addTaskButton').on('click',function() {
$('#tasksTableDiv').append('<div class="row" id="2">'
+ '<div id="description_2"'
+ 'class="col-sm-2 taskDescriptionCol">Description 2'
+ '</div>'
+ '<div class="col-sm-1 removeTaskCol">'
+ '<input id="button_2" class="removeTaskButton" type="button" value="X">'
+ '</div>'
+ '</div>');
});