Live events with on() instead of live()?
Live events with on() instead of live()?
Hello,
I have been wanting to use live events as explained here : http://datatables.net/release-datatables/examples/advanced_init/events_live.html
This actually works well, using the live() function.
However, jQuery recommends now using on() instead of live(). See http://api.jquery.com/live/
I tried replacing the live() function by on() and my code stopped working.
I just wanted to know if you will support on() and if the problem is even linked to datatables itself.
I am using jquery 1.8.1 and datatables 1.9.3
Best regards.
I have been wanting to use live events as explained here : http://datatables.net/release-datatables/examples/advanced_init/events_live.html
This actually works well, using the live() function.
However, jQuery recommends now using on() instead of live(). See http://api.jquery.com/live/
I tried replacing the live() function by on() and my code stopped working.
I just wanted to know if you will support on() and if the problem is even linked to datatables itself.
I am using jquery 1.8.1 and datatables 1.9.3
Best regards.
This discussion has been closed.
Replies
I'll be updating all of the documentation on the DataTables site as part of the work on 1.10 to use live, but in general, it has nothing to do with DataTables, since you are just using a jQuery event handler.
Allan
[code]
//Clickable Rows
$("#example tbody tr").live("click", function() {
//Disable the edit button
if($(this).hasClass('row_selected')){
$(this).removeClass('row_selected');
$("#btn-row-edit").button({disabled: true});
}
//Enable the edit button
else {
oTable.$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
$("#btn-row-edit").button({disabled: false});
}
});
[/code]
I'll look into changing it based off allan's suggestion. I cannot remember why i didn't change over to .on() i think it may have been because i could not use the $(this) function.
$("#example tbody").on("click", 'tr', function() {
[/code]
should work just fine.
Allan
I can't get everything to work correctly using on() with FixedColumns though. However, this is a just a sidenote which I can't get more into detail right now.