Update find.xml#1135
Merged
Merged
Conversation
"The elements will be filtered by testing whether they match this selector." isn't exactly accurate, as any selector in the selector list that isn't a descendant of the originating element gets excluded per https://github.com/jquery/jquery/blob/cf84696fd1d7fe314a11492606529b5a658ee9e3/external/sizzle/dist/sizzle.js#L306 "qSA considers elements outside a scoping root when evaluating child or descendant combinators, which is not what we want. In such cases, we work around the behavior by prefixing every selector in the list with an ID selector referencing the scope context." This is an important note, because it is contrary to how the native JS `querySelectorAll` function works, which doesn't do any such excluding (see https://stackoverflow.com/questions/56156003/jquery-find-not-finding-elements-that-match-this-selector)
mgol
reviewed
May 15, 2019
| <longdesc> | ||
| <p>Given a jQuery object that represents a set of DOM elements, the <code>.find()</code> method allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements. The <code>.find()</code> and <code>.children()</code> methods are similar, except that the latter only travels a single level down the DOM tree.</p> | ||
| <p>The first signature for the <code>.find()</code>method accepts a selector expression of the same type that we can pass to the <code>$()</code> function. The elements will be filtered by testing whether they match this selector. The expressions allowed include selectors like <code>> p</code> which will find all the paragraphs that are children of the elements in the jQuery object.</p> | ||
| <p>The first signature for the <code>.find()</code>method accepts a selector expression of the same type that we can pass to the <code>$()</code> function. The elements will be filtered by testing whether they match this selector, and that each selector in the list is a descendant so that elements outside the scoping root are not considered. The expressions allowed include selectors like <code>> p</code> which will find all the paragraphs that are children of the elements in the jQuery object.</p> |
Member
There was a problem hiding this comment.
The wording "each selector in the list is a descendant" is not perfectly clear to me as meaning that all parts of the selector must lie inside of the element. How about:
The elements will be filtered by testing whether they match this selector; all parts of the selector must lie inside of an element on which
.find()is called.
Contributor
Author
There was a problem hiding this comment.
That sounds pretty good to me, I think that definitely gets the idea across without being vague
Member
|
Thanks for the PR! Landed; sorry for the delay. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"The elements will be filtered by testing whether they match this selector." isn't exactly accurate, as any selector in the selector list that isn't a descendant of the originating element gets excluded per https://github.com/jquery/jquery/blob/cf84696fd1d7fe314a11492606529b5a658ee9e3/external/sizzle/dist/sizzle.js#L306
"qSA considers elements outside a scoping root when evaluating child or
descendant combinators, which is not what we want.
In such cases, we work around the behavior by prefixing every selector in the
list with an ID selector referencing the scope context."
This is an important note, because it is contrary to how the native JS
querySelectorAllfunction works, which doesn't do any such excluding (see https://stackoverflow.com/questions/56156003/jquery-find-not-finding-elements-that-match-this-selector)