$(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'); }) }).
$(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'); }) }).
It is working. The last option. Can you explain me about this document.
Onclick = function vs bind.? could you please just take a look at the first answer and its comments. If you have time.Thanks. – Jayapal Chandran Sep 23 '10 at 6:21 the bind function "binds" an event to an object with 'addEventListener'.
So document. Onclick attaches an event to the document and bind can bind events to (nearly) every element.In jQUery you can also bind custom events $('#myel'). Bind('myevent', function(){}); and trigger this with $('#myel').
Trigger('myevent'); – revaxarts Sep 23 '10 at 6:55 oh.ok. What if I am creating a native js class without using jquery to show a dialog and to add a callback function to the ok buttons onclick. Hope you can understand me.
I have already explained in quesiton and in the other answers comments. Suggestions will be fine. – Jayapal Chandran Sep 25 '10 at 13:09 the jquery bind() is just a wrapper function.
IE doesn't know the addEventListener.It uses attachEvent instead. JQuery checks the client is IE just use a function from above – revaxarts Sep 29 '10 at 14:45.
You're attaching multiple event handlers, one each .bind() call, just don't call this multiple times: $('#okbuttonid'). Bind('click',function() { alert('here'); }) an you won't get multiple alerts...just call it once on document. Ready, for example: $(function() { $('#okbuttonid').
Bind('click',function() { alert('here'); }) }).
I have expanded my question with additional real example. Please see the section after the heading "I am editing/adding the following after the first answer by Nick Craver" – Jayapal Chandran Sep 22 '10 at 11:35 @Jayapal - I don't understand your aversion to document.ready...this is exactly what it's used for. The native works because you replacing the onclick, which is still extra unneeded work, why not just bind once and not do that extra work?
– Nick Craver? Sep 22 '10 at 11:38 because, as I have said the div and the ok button will be totally dynamic. In this case how do I include in document.
Ready? – Jayapal Chandran Sep 22 '10 at 11:40 @Jayapal - You can use .live() to bind it once on ready and do nothing when it loads, for example: $(function() { $('#okbuttonid'). Live('click',function() { alert('here'); }); }); – Nick Craver?
Sep 22 '10 at 11:43 oh. I used live inside the changestatus function. But you have said it to use during document ready.
But still I was not able to solve my question... what about removing the bind? – Jayapal Chandran Sep 22 '10 at 11:50.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.