-
Notifications
You must be signed in to change notification settings - Fork 20.6k
closest: remove exception for pos selectors #2796
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
Comments
Hmmm. The Even if the property was still present, |
Deprecation aside, you wouldn't need to be able to pass context to matchesSelector for it to work as documented but rather just update the loop condition as mentioned. The documentation implies that this.context will be used in place of context if context is not passed. Since passing context works as expected, you could certainly do the same with this.context. That said, I think most people would be confused by it actually working as documented. Since it generally doesn't work as documented (and hasn't for many releases--if ever), I would think it would be better to remove the "this.context" portion of the "pos" creation and just remove that line from the documentation. As it is now, it is inconsistent as using ":first" in your selector will use the context but without it it won't, etc. (Not sure if any of this matters in the end if 3.0 is in the works and there will be no further 2.x releases, not familiar with the current release schedule. Obviously if this.context is removed entirely it will need to be removed here anyway.) |
Discussed in the meeting today. Since |
But currently the context parameter is used for all selectors. It is in the loop condition so the loop ends once the context element is reached, thereby not continuing any further up the dom. The only possible issue I see with the context parameter is if the context is not an ancestor element then it is basically "not used" for non positional selectors. |
Yeah, true, the docs need to be clear about what "used" means. I was thinking in terms of being the root of the tree from which selector strings are evaluated. I agree it is currently the point at which we stop trying to match, which is a different thing.
|
The context parameter has two effects: a cap on upward traversal, and a root for positional selectors and non-string selectors (another latent bug, by the way). The first is of arguable value but (as noted above) fails for any element in the collection that does not descend from it, but the second seems utterly pointless ( I'd prefer to drop the parameter completely, but at minimum I think the positional selector interaction should be removed. |
I can see the cap on upward traversal being useful in the context of a component on the page that could be embedded in arbitrary markup. Still, in cases where I personally have wanted to use
Yeah, I tried to think of a reason for using If we can come to an agreement on this I can put together a PR. At minimum we need to remove |
Yeah, I think we should just return empty whenever the selector is positional rather than try to get clever. As for the second argument, it feels like an underpowered |
I see the point your making with the nested div example but just want to point out that the context parameter here has to be a dom element. Passing a jquery object as in your example has no effect at all with non-positional selectors. I suppose you could consider that another bug, but the documentation does define it as a dom element so not really a bug. |
I agree about the error in the example @kingjiv but even when corrected it's the same result. http://jsbin.com/ququlisabu/1/edit?html,js,console |
So, I think we already deprecated the context argument. The docs even say that it was removed in 1.8, but it's still around. Perhaps all we need to do is actually remove it in 3.0. |
Nevermind, that's a different signature. |
Per meeting, closing this in favor of docs clarification. |
Well, aside from removing the pos exception. |
Further discussion here: http://stackoverflow.com/questions/34580013/jquery-closest-default-context
The documentation for closest states:
However, it seems that this is often not the case. You can see this illustrated here:
https://jsfiddle.net/pjbg4398/
When the context is passed explicitly, closest works as expected and only finds an element if it is within the context element. However, if the jquery set has a context and closest is called without explicitly passing a context, no context is used (contradicting the documentation). However, if the selector passed to closest contains non-css selectors (gt, eq, etc.), then the set's context is used.
I believe the fix should be to change the loop condition as follows:
should become:
which would be in line with the non-css code which does a similar thing with context:
The text was updated successfully, but these errors were encountered: