これは私が犯している恥ずかしいほど単純な間違いだと感じていますが、現時点ではそれを見ることができません。
行を動的に追加するテーブルがあります。各行の最後の列には、クリックするとその行を削除するリンクが含まれています。現在、行は正常に追加されていますが、削除ボタンにアタッチされているイベントが発生しない理由がわかりません。console.log()でテストするために削除コードを削除しましたが、コンソールに何も表示されません。
on()は追加されたHTMLで動作するはずですが、何が欠けていますか?
HTML:
<div id="people">
<table>
<tr>
<th>First Name</th>
<th>Second Name</th>
<th>Age</th>
</tr>
</table>
</div>
<a href="#" id="add">Add</a>
JS:
var html = '<tr>';
html += '<td><input type="text" /></td>';
html += '<td><input type="text" /></td>';
html += '<td><input type="text" /></td>';
html += '<td><a href="#" class="remove_btn">x</a></td>';
html += '</tr>';
$('.remove_btn').on('click', function() {
console.log('REMOVE BUTTON CLICKED');
//$(this).parent().parent().remove();
return false;
});
$('#add').on('click', function() {
$('#people').append(html);
return false;
});