-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
:visible/:hidden selectors unreliable #2227
Comments
|
Thank you for opening an issue. While you are correct that the behavior may be unexpected, the selector is working as documented. While the behavior differs between Firefox and Chrome, Chrome reports zero width and zero height, which technically means it is not visible according to our docs...
The fact the hidden elements can have visible content can seem strange, but it's the way it is in Chrome. But more importantly, the cost of working around this would be far greater than we are willing to deal with. I don't think this is the only edge case where the |
|
This seems like a Chrome bug, does Safari have it as well? |
Yes. |
|
Here's a test case: http://jsfiddle.net/2tgw2yr3/ Both jsbin.com and browserstack.com are down for me at the moment. |
|
@timmywil thank you for a quick reply. First of all I'd like to apologize, I did file a duplicate issue. It seems that there's at least one earlier issue #1855 reporting this problem, which includes a solution. Also, while it doesn't seem strange to that not visible elements can bleed visible child elements. For the edge case degree, perhaps there should be a note in the documentation then. IMO people use jQuery to get the same results in different browsers no matter what, and they may not even realize that their selectors will sometime behave differently. |
|
Funny, I thought I remembered an issue like this where The |
|
@dmethvin How old was it? @shimonenator already found #1855, and the only other case that comes to my mind is the soon-to-be-merged #2043 (which uses |
I know you love to say this as much as possible, but it's really not helpful for developers writing general purpose code, and the performance problems are irrelevant for many use cases. |
If it's that simple and |
|
I think you meant return !!((elem.offsetWidth && elem.offsetHeight) || elem.getClientRects().length)As such, following the current implementation where return (!elem.offsetWidth || !elem.offsetHeight) && !elem.getClientRects().lengthThus, it seems to me that |
|
Upon deeper analysis, this would not be a behavior change if it makes it in for 3.0, which I strongly recommend. The git builds include 10399dd (defining |
|
Actually, it looks like the proposed solution breaks the |
|
Ah, a slight behavior change, then. I'm still in favor of the |
|
In that case, what about dropping |
|
I would make such a decision entirely on performance. My untested supposition is that offset properties are faster than |
|
I'll do some testing. |
|
Ok, looks like performance necessitates keeping There's no difference for hidden elements, but it's about 2x slower in Chrome for visible elements to only use |
- Reverts behavior from 10399dd, which we never released. BR and inline elements are considered visible. - The possibility of dropping .offsetWidth and .offsetHeight was debunked by this perf: http://jsperf.com/visible-hidden-and-getclientrects Fixes jquerygh-2227
- Reverts behavior from 10399dd, which we never released. BR and inline elements are considered visible. - The possibility of dropping .offsetWidth and .offsetHeight was debunked by this perf: http://jsperf.com/visible-hidden-and-getclientrects Fixes gh-2227 Close gh-2281
|
Sorry for being late to the proposed and accepted PR, but it does not fix the issue. Please refer to my original issue description and a follow up comment. |
|
@shimonenator Had we wanted to keep the logic that was there, your suggestion would be right. However, the change was intentional. |
|
My apologies for commenting on a closed issue, but I believe this case warrants review. Using ClientRectList.prototype.length an anchor tag with no text is "visible", not to mention one with child elements which have no dimension either. Please consider https://github.com/FesterCluck/jquery/blob/master/src/css/hiddenVisibleSelectors.js If this is not part of the new intended behavior, my apologies. |
- Reverts behavior from 10399dd, which we never released. BR and inline elements are considered visible. - The possibility of dropping .offsetWidth and .offsetHeight was debunked by this perf: http://jsperf.com/visible-hidden-and-getclientrects Fixes gh-2227 Close gh-2281
Issue
This issue is present in both version 1 and 2 of jQuery.
It is happening on inline elements wrapping block elements, which is valid in HTML5, such as a header and an image wrapped in a single anchor.
Two issues arise:
Example
Solution
There are 2 potential solutions that come to mind, but each has flaws
The text was updated successfully, but these errors were encountered: