Categories
JavaScript

JavaScript events and the bind() function

The format is: 

$('#selector').bind('click', myData, functionName);
The first argument (in this case click) is the event attached to the element.
The second argument is a data structure, to pass more data to the handling function.
The third argument is the handing function itself. It can be an anonymous function.
Example of usage:
var linkVar = { message:'Hello from a link'};
var pVar = { message:'Hello from a paragraph};
function showMessage(evt) {
    alert(evt.data.message);
}
$('a').bind('click',linkVar,showMessage);
$('p').bind('mouseover',pVar,showMessage);