Skip to content

Commit 153f1ea

Browse files
committed
Add notes on cascadia behavior that may differ from jQuery`s
1 parent 2095230 commit 153f1ea

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Utility functions that are not in jQuery but are useful in Go are implemented as
8989

9090
The complete [package reference documentation can be found here][doc].
9191

92-
Please note that Cascadia's selectors do not necessarily match all supported selectors of jQuery (Sizzle). See the [cascadia project][cascadia] for details. Invalid selector strings compile to a `Matcher` that fails to match any node. Behaviour of the various functions that take a selector string as argument follows from that fact, e.g. (where `~` is an invalid selector string):
92+
Please note that Cascadia's selectors do not necessarily match all supported selectors of jQuery (Sizzle). See the [cascadia project][cascadia] for details. Also, the selectors work more like the DOM's `querySelectorAll`, than jQuery's matchers - they have no concept of contextual matching (for some concrete examples of what that means, see [this ticket](https://github.com/andybalholm/cascadia/issues/61)). In practice, it doesn't matter very often but it's something worth mentioning. Invalid selector strings compile to a `Matcher` that fails to match any node. Behaviour of the various functions that take a selector string as argument follows from that fact, e.g. (where `~` is an invalid selector string):
9393

9494
* `Find("~")` returns an empty selection because the selector string doesn't match anything.
9595
* `Add("~")` returns a new selection that holds the same nodes as the original selection, because it didn't add any node (selector string didn't match anything).

traversal.go

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const (
2020
// Find gets the descendants of each element in the current set of matched
2121
// elements, filtered by a selector. It returns a new Selection object
2222
// containing these matched elements.
23+
//
24+
// Note that as for all methods accepting a selector string, the selector is
25+
// compiled and applied by the cascadia package and inherits its behavior and
26+
// constraints regarding supported selectors. See the note on cascadia in
27+
// the goquery documentation here:
28+
// https://github.com/PuerkitoBio/goquery?tab=readme-ov-file#api
2329
func (s *Selection) Find(selector string) *Selection {
2430
return pushStack(s, findWithMatcher(s.Nodes, compileMatcher(selector)))
2531
}

0 commit comments

Comments
 (0)