I'm adding a new row into the table which is called people_table
using the following code:
$("#add_new_row").click(function() {
console.log("***");
$('table#people_table').append('<tr><td>Dima</td><td>Petrov</td><td>30</td><td><button type="button" class="btn btn-success" id="change_4">Change</button></td></tr>');
});
...
<button type="button" class="btn btn-primary" id="add_new_row">Add new row</button>
<table class="table table-hover" id="people_table">
<tr>
<th>Name</th>
<th>Surname</th>
<th>Age</th>
<th>Modify</th>
</tr>
{% for person in people %}
<tr>
<td>{{ person[1] }}</td>
<td>{{ person[2] }}</td>
<td>{{ person[3] }}</td>
<td><button type="button" class="btn btn-success" id="change_{{ person[0] }}">Change</button></td>
</tr>
{% endfor%}
</table>
But after adding the row the following function
$("button[id^='change_']").click(function() {
console.log("+++");
});
does not work for the button in the new added row, but it works for other buttons. What's the problem?