My goal is to bind to many elements on the page (using the on () function), and then unbind to a specific element (using off ()) after clicking it.
$(document).on({ mouseenter: enter, mouseleave: leave, mousedown: down, mouseup: up, click: click }, ".up_side .thumbsUp");
The on () function works well, but I cannot figure out how to use off () to unpin from a clicked element.
var click = function() { var thumbsUp = $(this); var successCallback = function(data) {
Thanks!!!
Decision
Use .data () to save the flag and check the flag before executing the code. This seems like a workaround and makes the code more fragile. If someone finds a better way, send it back. Thanks!
$(document).on({ mouseenter: function(){ if ($(this).data("submitted") != true) { $(this).css("cursor", "pointer"); $(this).css("backgroundPosition", "-48px"); } }, mouseleave: function(){ if ($(this).data("submitted") != true) { $(this).css("backgroundPosition", "0px"); } }, mousedown: function() { if ($(this).data("submitted") != true) { $(this).css("backgroundPosition", "-96px"); } }, mouseup: function() { if ($(this).data("submitted") != true) { $(this).css("backgroundPosition", "0px"); } }, click: function() { if ($(this).data("submitted") != true) { var thumbsUp = $(this); var ballotBox = $(thumbsUp).parent(); var votingStation = $(ballotBox).parent();
source share