New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.is(':hover') doesn't work with multiple elements #4154

Closed
Getfree opened this Issue Aug 12, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@Getfree

Getfree commented Aug 12, 2018

In this example, the second Javascript line fails.

<div></div>
<span></span>
console.log( $('div').is(':hover') ) ; //this line works fine
console.log( $('div, span').is(':hover') ) ; //this line throws an exception

Jsfiddle here: http://jsfiddle.net/kbohu58w/9/

The documentation for .is() says that it returns true if at least one of the elements matches the selector.
Which means .is(':hover') should work for multiple elements. But as the example shows, it doesn't.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil Aug 13, 2018

Member

The :hover selector is not officially supported by jQuery, but it does work when the qSA path is taken, as in the first example. I'll check with the team to see if we're aware of any bugs with the selector in currently supported browsers and if we might be able to add support for this. I can tell you that testing hover is tricky.

Member

timmywil commented Aug 13, 2018

The :hover selector is not officially supported by jQuery, but it does work when the qSA path is taken, as in the first example. I'll check with the team to see if we're aware of any bugs with the selector in currently supported browsers and if we might be able to add support for this. I can tell you that testing hover is tricky.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil Aug 13, 2018

Member

We discussed this in the meeting and agreed that the implementation for this selector is not pretty. That said, we plan to rewrite Sizzle in a way that relies much more heavily on qSA and matches, which would provide support for :hover. I'll close this as it is covered by Sizzle's Roadmap.

Member

timmywil commented Aug 13, 2018

We discussed this in the meeting and agreed that the implementation for this selector is not pretty. That said, we plan to rewrite Sizzle in a way that relies much more heavily on qSA and matches, which would provide support for :hover. I'll close this as it is covered by Sizzle's Roadmap.

@timmywil timmywil closed this Aug 13, 2018

@Getfree

This comment has been minimized.

Show comment
Hide comment
@Getfree

Getfree Aug 13, 2018

I wouldn't support this in Sizzle at all. Selectors like :hover:has(div) wouldn't work, end of story.
However, when the selector is entirely supported by querySelectorAll, it's trivial to make :hover work for multiple elements.

Actually, I'm currently using a customized version of jQuery 2.2.4 which solves that problem. I completely bypass Sizzle if the selector works with querySelectorAll.

Getfree commented Aug 13, 2018

I wouldn't support this in Sizzle at all. Selectors like :hover:has(div) wouldn't work, end of story.
However, when the selector is entirely supported by querySelectorAll, it's trivial to make :hover work for multiple elements.

Actually, I'm currently using a customized version of jQuery 2.2.4 which solves that problem. I completely bypass Sizzle if the selector works with querySelectorAll.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil Aug 13, 2018

Member

Selectors like :hover:has(div) wouldn't work, end of story

Actually, with the rewrite, they would.

Member

timmywil commented Aug 13, 2018

Selectors like :hover:has(div) wouldn't work, end of story

Actually, with the rewrite, they would.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment