When you 'click' on an object, Javascript fires a 'onClick' event (or 'click' for our purposes).

When we use:
$('myDiv').addEvent('click', function(){
     ....
});

This tells Javascript to listen for a 'click' event on the object 'myDiv'.
Note: An object could be anything on your HTML page "<div id='myDiv'>Click my</div>" would be a object called "myDiv"

When Javascript 'invokes' the function connected to that click event it passes along the information for the click event.

Example:
$('myDiv').addEvent('click', function(event){
     // The variable 'event' is passed to this function
     // and could be used
});

"event.target" would return the object that you clicked on (in this case the 'myDiv' object).

Question: Can you guess what "event.target.id" would be?
Answer: if you said a string containing the word 'myDiv' you would be correct!

Suggestion:
If you do not have 'firebug' a Firefox plugin you should get it immediately, it will help by letting you look inside the objects on any html page.
It will work with everything JavaScript, Mootools or jQuery etc.

Reply via email to