How to add OnClick event on Datatables TR/TD

How to add OnClick event on Datatables TR/TD

agesoneagesone Posts: 7Questions: 0Answers: 0
edited August 2011 in General
Doesn't seem to work when i just do it normally, anything i should be doing differently?

Replies

  • aaronwaaronw Posts: 89Questions: 3Answers: 4
    Define normally - can you post some code?
  • GregPGregP Posts: 500Questions: 10Answers: 0
    "Normal" onClick events are added inline to anchor tags, and won't work with TR/TD. But that's OK, because inline onClick is considered bad practice these days.

    What you'll want to do is use jQuery to bind a click event using either .click(), .delegate(), or .live(), probably as part of a function called by a callback such as fnInitComplete.
  • allanallan Posts: 63,528Questions: 1Answers: 10,473 Site admin
    Yup, as Greg says, avoid DOM0 methods, and use either DOM2 or just use jQuery events:

    [code]
    $('#example_table td').click( function () {
    ....
    } );
    [/code]

    will do it.

    See examples here:
    http://datatables.net/release-datatables/examples/advanced_init/events_pre_init.html
    http://datatables.net/release-datatables/examples/advanced_init/events_live.html

    Allan
This discussion has been closed.