Button in the header. How to handle event?

Button in the header. How to handle event?

jonjvaughnjonjvaughn Posts: 2Questions: 1Answers: 0

I am using the technique described here to add a button to my table header:
$(document).ready(function() {
$('#example').DataTable( {
"dom": '<"toolbar">frtip'
} );

$("div.toolbar").html('<button type="button">Click Me!</button>');

} );

However after that I am stuck not knowing how to detect and act on the click. Thank you in advance.

This question has an accepted answers - jump to answer

Answers

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16
    Answer ✓

    @jonvaughn, you could try to add this part after the line you showed in your example:

      $("div.toolbar").find("button").off().on("click", function (e) {
        alert("Did it work?");
      });
    

    Hope this helps,

  • jonjvaughnjonjvaughn Posts: 2Questions: 1Answers: 0

    Excellent for what I need. Thank you.

This discussion has been closed.