Bind multiple events to jQuery 'live' method

后端 未结 4 2018
梦谈多话
梦谈多话 2020-12-31 03:34

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 el

4条回答
  •  醉酒成梦
    2020-12-31 04:12

    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
      }
    });
    

提交回复
热议问题