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

rauls4rauls4 Posts: 10Questions: 0Answers: 0
edited March 2014 in General
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.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    So your fnFormatDetails record there is returning just a string, which is why it isn't working - jQuery is selecting `.del` class elements, but there isn't any when that selector runs.

    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
  • rauls4rauls4 Posts: 10Questions: 0Answers: 0
    Brilliant! Thanks Allan!
This discussion has been closed.