Event handlers in Jquery
Event handlers in Jquery
brentjrussell
Posts: 2Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
[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