jQuery Trigger Click Event not working on Button on Row

jQuery Trigger Click Event not working on Button on Row

enigmacloughenigmaclough Posts: 8Questions: 3Answers: 0

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

Sign In or Register to comment.