Miguel Flores Miguel Flores - 1 month ago 10
Javascript Question

Execute a function from dynamic button

I'm creating a table, after that I convert table to jQuery dataTable, for this I'm using

dataTable.responsive
and an option to display information in a modal, problem here is that my function button is only displayed on the modal, so my question is what can I do to access to that button, I'm trying doing this but do not work.

$('#TableBody').on('click', '.glyphicon-edit', function () {
alert("Click!");
});


This do not work too:

//example is my table id
$('#example').on('click', '.glyphicon-edit', function () {
alert("Click!");
});


Here is my full code to see my problem properly.

Answer

If you're using Bootstrap styling, use the code below. This will narrow your selector to the element in the modal opened by jQuery DataTables.

$(document).on('click', '.dtr-bs-modal .glyphicon-edit', function(){
   // ... skipped ...
});
Comments