I using http://datatables.net for sorting my tables.
I generate json and loading rows in table. For one record I creating custom with custom class.
<td class=""><span class="qty_new" data-id="1">50</span></td>
$(document).ready(function() {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": "ajax/tables/ajax.php"
});
$('.qty_new').click(function() {
alert(1000);
});
});
This code not returning alert (1000) and I don’t know why.
It’s because the
.qty_newfield is being created by datatables after the page has loaded. Therefore you have to delegate the event listener to a parent element. Try this:Or for older versions of jQuery, use
delegate():I’ve used
tableas the parent selector here, in your code it should be the single closest static element.