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