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 1079083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:49:00+00:00 2026-05-16T21:49:00+00:00

I have a button named okbutton. A callback function is bind to the click

  • 0

I have a button named okbutton.

A callback function is bind to the click event of the okbutton during page load

$('#okbuttonid').bind('click',function() { alert('here'); })

The first time i click the okbutton it alerts once. as expected.

When i click the next time it alerts twice and for the third time it alert thrice and it goes on. same is for $('#okbuttonid').click = function() { alert('here'); }

But

when i do it like

document.getElementById('okbuttonid').onclick = function() { alert('here'); }

it alerts only once. for every click it alerts only once.

when is with the bind event.

it it like that the alert is called the number of times we bind its event.

why is it so?

do we have to remove every time we bind.

Shall i use the native event style instead of bind?

The native event bind is working well but i want to know what this jquery bind does


I am editing/adding the following after the first answer by Nick Craver


  1. I have a list which needs a change status option(totally 4 options).
  2. I display a change status link which when clicked displays a status box and on ok button which is positioned absolutely above the change status link.
  3. i display it like a tooltip popup.
  4. at the time of showing the statuschange popup i am attaching the okbutton onclick to a function which when clicked sends an ajax request.
  5. above is my scenario.

for this i dont want to use document.ready

my code is like the following

<div id='statusdiv' style='display:none; position:absolute;'><!-- and more styles -->
<select><!-- list of options --></select>
<input id='okbutton' value='OK'>
</div>

when the user clicks changestatus link i show this div and bind a callback for the click event of okbutton.

this html part could be totally dynamic so no inline event attach.

function changestatus()
{
   //display the statusdiv absolutely above the mouse event triggered place
   $('#okbutton').bind('click',function() {
     //ajax request
   })
}

The native event bind is working well but i want to know what this jquery bind does

  • 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-16T21:49:00+00:00Added an answer on May 16, 2026 at 9:49 pm
    $(function() {
      $('#okbuttonid').bind('click',function() { alert('here'); })
    });
    

    is fine, since the okbutton is allready in the DOM.

    try

    $(function() {
      $('#okbuttonid').live('click',function() { alert('here'); })
    });
    

    to bind the event to the document and the click event bubbles up to the document and triggers the function

    a much better way is to use delegate:

    $(function() {
      $('#parentOfokbutton').delegate('#okbutton','click',function() { alert('here'); })
    });
    

    this binds the event to ‘parentOfokbutton’ an is nearly the same as the ‘live’ function but the event don’t has to bubble up the DOM

    if you still want to use the bind function (for some reason) prepend an unbind methode:

    $(function() {
         $('#okbuttonid').unbind('click').bind('click',function() { alert('here'); })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main window with a Gtk Button named openDialog. If I click
I have a folderBrowserDialog control and i have a button named click i did
I have three button named(titled) hello, nothing, heaven and one label (IBOutlet UIlabel lab).
I have a radio button named Choose with the options yes and no. If
I have a Windows Form application with a button named loginBtn and a label
hi i have property named. public bool ShowLabels{get; set;} and one toolbar menu button
I have two button name A, and B want to click them equal to
I have a jQuery code: $('a[name=dialog]').click(function(e) { var param = $(this).attr(name); var param =
I have used click_no_wait to click a button and then used javascript_dialog.button('OK').click to click
I have a button named yes and another named no . <input type=button name=yes

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.