Skip to content

Update find.xml#1135

Merged
mgol merged 2 commits into
jquery:masterfrom
BrianLeishman:patch-1
Aug 29, 2019
Merged

Update find.xml#1135
mgol merged 2 commits into
jquery:masterfrom
BrianLeishman:patch-1

Conversation

@BrianLeishman
Copy link
Copy Markdown
Contributor

"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)

"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)
@jsf-clabot
Copy link
Copy Markdown

jsf-clabot commented May 15, 2019

CLA assistant check
All committers have signed the CLA.

Comment thread entries/find.xml Outdated
<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>&gt; 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>&gt; p</code> which will find all the paragraphs that are children of the elements in the jQuery object.</p>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds pretty good to me, I think that definitely gets the idea across without being vague

@mgol mgol merged commit 92a40f6 into jquery:master Aug 29, 2019
@mgol
Copy link
Copy Markdown
Member

mgol commented Aug 29, 2019

Thanks for the PR! Landed; sorry for the delay.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants