Can't get jQuery to select a button defined inside a detail layou
Can't get jQuery to select a button defined inside a detail layou
So, when the disclosure button on my cell is clicked, I show the details defined in me fnFormatDetails function:
[code] function fnFormatDetails( dTable, nTr )
{
var oData = dTable.fnGetData( nTr );
var sOut =
''+
''+
''+
'Active:'+oData.active+''+
'Temperature Units:'+oData.temperature_units+''+
'Auto Rotate:'+oData.auto_rotate+''+
''+
'Delete Device'+
'';
return sOut;
};
[/code]
But when I ask jQuery to catch clicks selecting by class name, nothing happens.
[code]
$(".del").click(function(){
alert("Howdy!");
});
[/code]
Any tips? The reason I have a button on the detail screen is because that is where the user will get the option to delete the item from that table.
[code] function fnFormatDetails( dTable, nTr )
{
var oData = dTable.fnGetData( nTr );
var sOut =
''+
''+
''+
'Active:'+oData.active+''+
'Temperature Units:'+oData.temperature_units+''+
'Auto Rotate:'+oData.auto_rotate+''+
''+
'Delete Device'+
'';
return sOut;
};
[/code]
But when I ask jQuery to catch clicks selecting by class name, nothing happens.
[code]
$(".del").click(function(){
alert("Howdy!");
});
[/code]
Any tips? The reason I have a button on the detail screen is because that is where the user will get the option to delete the item from that table.
This discussion has been closed.
Replies
My suggestion in this case would be to use a delegated event:
[code]
$('#myTable').on( 'click', 'button.del', function () {
alert( 'Giddy up' );
} );
[/code]
Add that just once - perhaps in the same function that you use to initialise the DataTable - and that will do it for all future instances of the delete button.
Allan