Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

jqLite handles on/off asymmetrically for mouseenter/mouseleave #12795

Closed
@VWoeltjen

Description

@VWoeltjen

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions