jqLite handles on/off asymmetrically for mouseenter/mouseleave #12795
Description
After an alternating series of on
/off
calls for mouseenter
or mouseleave
, the event listener starts being invoked more often than expected.
Say you have a reference to a jqLite-wrapped element, $element
, and you want to invoke some function when the mouse enters that element:
$element.on('mouseenter', someFn);
Now, someFn
is invoked once every time the mouse enters the DOM element wrapped by $element
, as expected.
Now detach that listener:
$element.off('mouseenter', someFn);
No, someFn
is no longer invoked when the mouse enters that DOM element, again as expected.
Now, reattach the listener:
$element.on('mouseenter', someFn);
Observe: Now someFn
is invoked twice whenever the mouse enters the specified DOM element, which is not expected.
More generally, after n calls to on
and n - 1 calls to off
, the event listener starts getting invoked n times per mouse entry, instead of once as expected.
This is true for mouseenter
and mouseleave
but does not appear to be the case for other events.
See this gist illustrating the issue.