views:

881

answers:

1

jQuery's 'live' method is unable to handle multiple events. Does anyone know of a good workaround to attach multiple events to a function that polls current and future elements? Or am I stuck using duplicate live methods for each event handler I need?

Example - I am trying to do something like:

$('.myclass').live('change keypress blur', function(){
  // do stuff
});
+3  A: 

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 mouseover and mouseout events at the same time like so:

$('.hoverme').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
    // do something on mouseover
  } else {
    // do something on mouseout
  }
});
cxfx