I have three plus (+) buttons next to three separate tables (built with DataTables). Since the pluses were created in one location (with DT), they're assigned the same classes and clicking on any of them opens the same modals.
I dynamically added classes to each of the pluses in order to add specificity. I'm trying to trigger an onClick event for the first +, but for some reason it's not working.
Here's my question: Why isn't my onClick event triggered? Do I have to add more specificity? Is the problem with where the button was created? (see code below)
Button creation
loadDataTable(_payload, _grid, _def) {
...
var table = $(_grid).DataTable({
data: _payload,
...
buttons: [
{
text: '<i class="fa fa-plus"></i>',
titleAttr: 'Add',
className: 'dtAddClass btn' + _grid
},
// this creates:
// btn 1: class="btn btn-default dtAddClass btn.rolesgrid"
// btn 2: class="btn btn-default dtAddClass btn.srchgrid"
// btn 3: class="btn btn-default dtAddClass btn.additionalsrchgrid"
// this is exactly what I want
onClick event:
$(document).on("click", ".btn.rolesgrid", disp._newRole); // this does not open the modal
$(document).on("click", ".dtAddClass, .btn.rolesgrid", disp._newRole); // this triggers all of the pluses to open modals, which I don't want. I'm guessing it has to do with the .dtAddClass
Method:
_newRole(e) {
dialog.dialog({ title: "Add New Search/Role Filled" });
dialog.dialog("open");
console.log('this is e: ' + e)
}