var handler = function() {
alert('The quick brown fox jumps over the lazy dog.');
};
$('#orange').bind('click', handler);
$('#orange').unbind('click', handler);
Passing Data to Event Handlers
var theData = "My data";
var handler = function(event) {
console.log(event.data);
};
$("#some-element").bind("click", theData, handler);
Hovering
$('.my_div').hover(hover_previous_in, hover_previous_out); function hover_previous_in() { console.log('in'); } function hover_previous_out() { console.log('out'); }
Learning Resources
- jQuery events tutorial.
- jQuery events with types tutorial.
- Safer event handling with jQuery namespaced events
- Using jQuery .on() and .off()