Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:36:18+00:00 2026-06-04T08:36:18+00:00

My goal is to bind to many elements on page (using on()) and then

  • 0

My goal is to bind to many elements on page (using on()) and then to unbind from a specific element (using off()) once it has been clicked.

$(document).on({
    mouseenter: enter,
    mouseleave: leave,
    mousedown: down,
    mouseup: up,
    click: click
}, ".up_side .thumbsUp");

The on() function is working well, but I can’t figure out how to use off() to unbind from the clicked element.

var click = function() {
    var thumbsUp = $(this);

    var successCallback = function(data) {
        // This is where I need to unbind the clicked element
        $(thumbsUp).off({
            mouseenter: enter, 
            mouseleave: leave
        });
    }

    $(this).castVote(direction, modelName, modelId, successCallback, errorCallback);
}

Thanks!!!


Solution

Use .data() to store a flag and check the flag before executing code. This does seems like a workaround and makes the code more brittle. If anyone finds a better way, please post 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();

            //ballotBox.hide(0, "", function() {
            var direction = $(thumbsUp).dataset("direction");
            var modelName = $(votingStation).dataset("modelName");
            var modelId = $(votingStation).dataset("modelId");

            var successCallback = function(data) {
                $(thumbsUp).css("backgroundPosition", "-144px");

                // Add flag to indicate successful vote 
                thumbsUp.data("submitted", true)

                $(this).vote_up_side('animateBallotBox', data, ballotBox, thumbsUp);
            }

            var errorCallback = function(XMLHttpRequest, textStatus, errorThrown) {
                $(this).vote_up_side('animateError', ballotBox);
            }

            $(this).castVote(direction, modelName, modelId, successCallback, errorCallback);
        }
    }
}, ".up_side .thumbsUp");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:36:19+00:00Added an answer on June 4, 2026 at 8:36 am

    The .off() documentation says:

    selector A selector which should match the one originally passed to .on() when attaching event handlers.

    and (my emphasis)

    To remove specific delegated event handlers, provide a selector argument. The selector string must exactly match the one passed to .on() when the event handler was attached.

    Hence it’s not possible AFAIK to selectively (no pun intended) remove some elements from a delegated event handler.

    I think your only option is to leave the event handler in place, but tag each element with some .data() which you use to indicate whether that particular element has already been clicked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In perl DBI , you can bind a hash element value to a specific
My goal: In case someone selects a specific value from an select box something
The following jQuery's goal is to load images from a server, and then control
I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
Goal : Our application is built using multiple types (e.g. Person, PersonSite(ICollection), Site -
goal : I want to place a text after the submit button using hook_form_alter.
I'm getting a compiler error with bind : using namespace std; bool odp(int arg1,
I am using the maven-eclipse-plugin to configure my eclipse workspace with the configure-workspace goal
http://jsfiddle.net/AYPze/9/ In this example I have two similar divs with the same goal. Bind
I do have a page that has a TextBox a Button and a Datagrid.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.