jQuery Trigger Click Event not working on Button on Row
jQuery Trigger Click Event not working on Button on Row
I have a datatable where each row has a HTML button element which when clicked performs further actions. The button works fine when clicked, however, when trying to use the jQuery trigger('click') function to programmatically trigger the click it does not work. There are no errors in the console.
var itsc_devices = $( '#itsc_devices').DataTable({
responsive: true,
initComplete: function( settings, json ) {
var filter = getCookie( 'devices_filter' );
console.log( $( '#device_history_button_' + filter ).length );
if ( $( '#device_history_button_' + filter ).length ) {
deleteCookie( 'devices_filter' );
$( '#device_history_button_' + filter ).trigger( 'click' );
}
}
});
console.log line output: 1 (confirms filter variable correct and button exists)
Cookie is deleted (confirming code is firing at this point)
Trigger event does not fire
Any suggestions please?
Answers
Its hard to say what the problem might be without seeing it. Doesn't sound like a Datatables specific issue but if you post a link to your page or a test case replicating the issue we'll take a look.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Maybe this SO thread will give some ideas.
Kevin