The on() method isn't supported in jQuery 1.4.x. Can someone tell me how to fix this so it's compatible?
$(document).on({
mouseenter: MyObj.mouseenter,
mouseleave: MyObj.mouseleave
}, '.class');
The on() method isn't supported in jQuery 1.4.x. Can someone tell me how to fix this so it's compatible?
$(document).on({
mouseenter: MyObj.mouseenter,
mouseleave: MyObj.mouseleave
}, '.class');
Use the delegate method.
$(document).delegate('.class',{
mouseenter: MyObj.mouseenter,
mouseleave: MyObj.mouseleave
});
Note: jQuery 1.4.3+ required
You should use live
instead of on
to make it compatible with old versions of jQuery. live
always works for the elements that will be created after the page has been loaded.
jQuery 1.7 deprecated live() method and 1.9 has removed it. It has been replaced by on
.
If you can however, it is wiser to just upgrade your jQuery.
Do not use bind
because this offers not the same functionality as live
.
You could apply various listeners directly to a jQuery object like so:
$(".class").mouseover(function() {
}).mouseout(function() {
});
... or this:
$(".class").mouseenter(function() {
}).mouseleave(function() {
});
Example available here: http://api.jquery.com/mouseenter/