How to define event of two button in datatable ?
How to define event of two button in datatable ?
headshot9x
Posts: 59Questions: 16Answers: 1
Hello guys, In datatable , i have two buttons, I want to define event each of button
{
"mData": null,
"aTargets": [-1],
"defaultContent": '<button type="button" id="bt1" class="btn1">Button1</button>'
},
{
"mData": null,
"aTargets": [-2],
"defaultContent": '<button type="button" id="bt2" class="btn2">Button2</button>'
},
And event jquery as follow:
$('#table tbody>bt1').on('click', 'button', function (e) {
console.log("button 1 is click");
});
$('#table tbody>bt2').on('click', 'button', function (e) {
console.log("button 2 is click");
});
When i click button 1 or button 2, i'm not see log in devtool Chrome.
Can you tell me about this, some mistake or wrong in here. ? Thank you.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I would suggest using:
And likewise for button 2. See the jQuery events documentation for how this works.
At the moment the selector
'#table tbody>bt1'
is not selecting anything (there are no direct decedents of thetbody
which have have the tag namebt1
. You might want to take a look into CSS selectors a bit as well since that is how jQuery typically selects elements.Allan