Search code examples
javascriptjquerydatatablesmousedown

Jquery mousedown not firing on datatables


Honestly flummoxed. This works when I fire it on the random div to log 'fun' to the console, but, if I change it to .select-checkbox or td I get no response.

The td cell in question does include a :before and an :after to render a checkbox-like-checkbox, so maybe there's some weird interference there...

    $('td.select-checkbox').mousedown(function(){
        console.log('fun')
     });

Alternatively, though I have trouble believing and/or googling this, the JQuery Docs seem to state that mousedown only works on divs... like maybe actual div


Solution

  • Perhaps the table cells are dynamically loaded and therefore the handler is not registered on page load correctly. In which case you can register it on 'body' instead:

    mousedown not working on dynamically loaded element