Not to confuse you, there are other options using Jquery. This binds the click event to your button ready to use even if the button had not been created in the dom yet. I give this example in case you ever get into Jquery Mobile because use ready() is a big no no. Also, if you are using a lot of Ajax and replacing the button using code snippets, the click event using bind will be lost but using on the click event says in tact.
<script type=”text/javascript” >
$(document).on('click',‘#btnTest’,function () {
Alert(‘ Button clicked’ )
}) ;
</script>
>I want to be sure that I understand one basic concept of event handing by Javascript or jQuery correctly.
>
>A very simple example:
>
>Page has a few buttons and a few input elements. One of the buttons ID is ‘btnTest’
>
>Here is the script in the Head section of the page:
>
><script type=”text/javascript” >
> $(document).ready(function () {
> FireClickMethod();
> });
> Function FireClickMethod() {
> $(‘#btnTest’).click( function () {
> Alert(‘ Button clicked’ )
> })
> }
></script>
>
>
>Does method FireClickMethod fire when user clicks on any of the buttons? Of course I understand that jQuery will look for element ‘btnTest’ and will determine if the click was on this button. But I just wanted to understand that method files FireClickMethod() on every click or other event on the page. Do I understand this correctly?