combine jquery .on() on multiple divs

I have this:

$('#MyDiv1').on({

   mouseenter: function () { SomeFunction(); },
   mouseleave: function () { SomeOtherFunction(); }

}, '.SomeClass');

$('#MyDiv2').on({

   mouseenter: function () { SomeFunction(); },
   mouseleave: function () { SomeOtherFunction(); }

}, '.SomeClass');

Basically, the handlers are the same for both MyDiv1 and MyDiv2 .

How do I combine them into one handler for both?

Thanks.


$('#MyDiv1, #MyDiv2').on({

   mouseenter: function () { SomeFunction(); },
   mouseleave: function () { SomeOtherFunction(); },

}, '.SomeClass');
链接地址: http://www.djcxy.com/p/83458.html

上一篇: 语法上适用于多个jQuery选择器的最佳实践

下一篇: 结合多个div上的jquery .on()