MCPcopy
hub / github.com/PuerkitoBio/goquery / ClosestMatcher

Method ClosestMatcher

traversal.go:136–147  ·  view source on GitHub ↗

ClosestMatcher gets the first element that matches the matcher by testing the element itself and traversing up through its ancestors in the DOM tree.

(m Matcher)

Source from the content-addressed store, hash-verified

134// ClosestMatcher gets the first element that matches the matcher by testing the
135// element itself and traversing up through its ancestors in the DOM tree.
136func (s *Selection) ClosestMatcher(m Matcher) *Selection {
137 return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
138 // For each node in the selection, test the node itself, then each parent
139 // until a match is found.
140 for ; n != nil; n = n.Parent {
141 if m.Match(n) {
142 return []*html.Node{n}
143 }
144 }
145 return nil
146 }))
147}
148
149// ClosestNodes gets the first element that matches one of the nodes by testing the
150// element itself and traversing up through its ancestors in the DOM tree.

Callers 1

ClosestMethod · 0.95

Calls 3

pushStackFunction · 0.85
mapNodesFunction · 0.85
MatchMethod · 0.65

Tested by

no test coverage detected