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

  • SEARCH
  • Home
  • 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 6011015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:11:55+00:00 2026-05-23T02:11:55+00:00

I am binding a click event with a button: $(‘#myButton’).bind(‘click’, onButtonClicked); In one scenario,

  • 0

I am binding a click event with a button:

$('#myButton').bind('click',  onButtonClicked);

In one scenario, this is getting called multiple times, so when I do a trigger I see multiple ajax calls which I want to prevent.

How do I bind only if its not bound before.

  • 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-05-23T02:11:56+00:00Added an answer on May 23, 2026 at 2:11 am

    Update 24 Aug ’12: In jQuery 1.8, it is no longer possible to access the element’s events using .data('events'). (See this bug for details.) It is possible to access the same data with jQuery._data(elem, 'events'), an internal data structure, which is undocumented and therefore not 100% guaranteed to remain stable. This shouldn’t, however, be a problem, and the relevant line of the plugin code above can be changed to the following:

    var data = jQuery._data(this[0], 'events')[type];
    

    jQuery events are stored in a data object called events, so you could search in this:

    var button = $('#myButton');
    if (-1 !== $.inArray(onButtonClicked, button.data('events').click)) {
        button.click(onButtonClicked);
    }
    

    It would be best, of course, if you could structure your application so this code only gets called once.


    This could be encapsulated into a plugin:

    $.fn.isBound = function(type, fn) {
        var data = this.data('events')[type];
    
        if (data === undefined || data.length === 0) {
            return false;
        }
    
        return (-1 !== $.inArray(fn, data));
    };
    

    You could then call:

    var button = $('#myButton');
    if (!button.isBound('click', onButtonClicked)) {
        button.click(onButtonClicked);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to bind a click event to a button within a usercontrol
I have some Backbone.js code that bind a click event to a button, and
Where should I store event methods for button Click event ?Normally it's store in
So I have a dynamically loaded button that is called with the following .live('click')
I can't figure out what is wrong for this simple binding. when click on
Check out this jsfiddle . There is a <div> with a click binding. This
I'm binding a click event to a div element, which is created after clicking
I had a problem with passing a parsed string to a button click event.
The following XAML produces a run-time Binding error when I click on an item
When binding multiple variables value1 value2 value3 in the same text field, do I

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.