Understanding the difference in a jquery on/off function
I have been coding up a page and come across something i do not understand.
the goal was to disable the context menu when a button was pressed and
enable it again later.
the first example disables the contextmenu but cant enable it again after.
Note: the 'off' command is obviously not run right after the 'on' command,
I have just pulled the relevant code out for readers convenience.
Can someone please explain to me why this doesnt work:
$(document).on("contextmenu",function(e){return false;});
$(document).off("contextmenu",function(e){return false;});
yet this does:
function returnFalse(e) {
return false;
}
$(document).on("contextmenu",returnFalse);
$(document).off("contextmenu",returnFalse);
No comments:
Post a Comment