1package goquery 2 3import "golang.org/x/net/html" 4 5// Is checks the current matched set of elements against a selector and 6// returns true if at least one of these elements matches. 7func (s *Selection) Is(selector string) bool { 8 return s.IsMatcher(compileMatcher(selector)) 9} 10 11// IsMatcher checks the current matched set of elements against a matcher and 12// returns true if at least one of these elements matches. 13func (s *Selection) IsMatcher(m Matcher) bool { 14 if len(s.Nodes) > 0 { 15 if len(s.Nodes) == 1 { 16 return m.Match(s.Nodes[0]) 17 } 18 return len(m.Filter(s.Nodes)) > 0 19 } 20 21 return false 22} 23 24// IsFunction checks the current matched set of elements against a predicate and 25// returns true if at least one of these elements matches. 26func (s *Selection) IsFunction(f func(int, *Selection) bool) bool { 27 return s.FilterFunction(f).Length() > 0 28} 29 30// IsSelection checks the current matched set of elements against a Selection object 31// and returns true if at least one of these elements matches. 32func (s *Selection) IsSelection(sel *Selection) bool { 33 return s.FilterSelection(sel).Length() > 0 34} 35 36// IsNodes checks the current matched set of elements against the specified nodes 37// and returns true if at least one of these elements matches. 38func (s *Selection) IsNodes(nodes ...*html.Node) bool { 39 return s.FilterNodes(nodes...).Length() > 0 40} 41 42// Contains returns true if the specified Node is within, 43// at any depth, one of the nodes in the Selection object. 44// It is NOT inclusive, to behave like jQuery's implementation, and 45// unlike Javascript's .contains, so if the contained 46// node is itself in the selection, it returns false. 47func (s *Selection) Contains(n *html.Node) bool { 48 return sliceContains(s.Nodes, n) 49} 50