The closest equivalent jQuery has is .bind()
, for example:
$("#element").bind('eventName', function(e) {
//stuff
});
And .unbind()
to remove the handler, like this:
$("#element").unbind('eventName');
There are also shortcuts for .bind()
, so for example click
can be done 2 ways:
$("#element").bind('click', function() { alert('clicked!'); });
//or...
$("#element").click(function() { alert('clicked!'); });
There is also .live()
(.die()
to unbind) and .delegate()
(.undelegate()
to unbind) for event handlers based on bubbling rather than being directly attached, e.g. for dynamically created elements.
The examples above were anonymous functions, but you can provide a function directly just like dojo (or any javascript really), like this:
$("#element").click(myNamedFunction);