Hi,
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
- I have a list which needs a change status option(totally 4 options).
- 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.
- i display it like a tooltip popup.
- at the time of showing the statuschange popup i am attaching the okbutton onclick to a function which when clicked sends an ajax request.
- 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