Event handlers in Jquery

Event handlers in Jquery

brentjrussellbrentjrussell Posts: 2Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
I have some event handlers on my row expand as shown in this example.

http://datatables.net/release-datatables/examples/api/row_details.html

As you can see from this code, it is also using the JQuery "live" handler to expand the row, such as

$('#example tbody td img').live('click', function () {

This was deprecated in version 1.9.1 of Jquery.

If I instead use, off/off as 1.9.1 recommends, it does not listen to my event. I was able to work around this issue by adding in the jquery migrate events for die/live to my code directly.

jQuery.fn.live = function (types, data, fn) {
jQuery(this.context).on(types, this.selector, data, fn);
return this;
};

jQuery.fn.die = function (types, fn) {
jQuery(this.context).off(types, this.selector || "**", fn);
return this;
};

However, I am curious as to why the data table doesn't naturally respond to the off/on event?

Thanks for your time,

Brent

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Change `$('#example tbody td img').live('click', function () {` to:

    [code]
    $('#example tbody').on('click', 'td img', function () {
    [/code]

    and it should work fine.

    I'm going to be upgrading the whole site soon to reflect the changes in jQuery.

    Allan
  • brentjrussellbrentjrussell Posts: 2Questions: 0Answers: 0
    Thank you for the reply. I came back to the forum just now to post a similar finding. It is great to hear confirmation I was on the right track. Have a great weekend.
This discussion has been closed.