私はjqueryとdatatablesを使って、編集と削除のボタンを動的に生成しています。私は後でjavascriptでそれらにアクセスする必要があり、私はそれを動作させることはできません。動的に生成されたボタンにアクセス
私はこのレンダリング機能があります。
render: function (data) {
var actions = '';
actions += '<div class="btn-group btn-group-xs">';
actions += '<div id="'+data.id+'" class="buttonUpdate btn btn-primary"><span class="glyphicon glyphicon-pencil"></span></div>';
actions += '<div id="'+data.id+'" class="buttonDelete btn btn-danger"><span class="glyphicon glyphicon-trash"></span></div>';
actions += '</div>';
return actions;
}
をそして、私はボタンが正しく表示され見ることができます。
私はイベントを取得しよう:
$('.buttonDelete').click(function() {
alert('button clicked');
console.log(this.id);
//window.location.href = "{!! route('employee') !!}/"+employee_id;
});
しかし、それは何もしていません:(
がどのように私は、イベントを取得することができますし、ボタンが正しく生成されている場合も、どのように私は見ることができます。 ?右のidとクラスで
チェックアウト[委任イベント](http://api.jquery.com/on/#direct-and-delegated-events)。ハンドラが初期化される前の要素に明示的に割り当てられているため、ハンドラは機能しません。動的に追加された要素は、親要素で伝播されたイベントを処理する必要があります。 –