How To Bind jQuery .live() To Multiple Events
erics, April 17th, 2011
As of jQuery 1.4.1 .live() can accept multiple, space-separated events, similar to the functionality provided in .bind(). For example, we can “live bind” the click and focus events at the same time like so:
1 2 3 |
jQuery('.datepick').live('click focus', function () { jQuery(this).datepicker('destroy').datepicker({showOn: 'both'}); }); |
Another example, this time creating a hover effect:
1 2 3 4 5 6 7 |
jQuery('.rollover').live('mouseover mouseout', function(event) { if (event.type == 'mouseover') { // do something on mouseover } else { // do something on mouseout } }); |