You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

  1. package goquery
  2. import "golang.org/x/net/html"
  3. // Add adds the selector string's matching nodes to those in the current
  4. // selection and returns a new Selection object.
  5. // The selector string is run in the context of the document of the current
  6. // Selection object.
  7. func (s *Selection) Add(selector string) *Selection {
  8. return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...)
  9. }
  10. // AddMatcher adds the matcher's matching nodes to those in the current
  11. // selection and returns a new Selection object.
  12. // The matcher is run in the context of the document of the current
  13. // Selection object.
  14. func (s *Selection) AddMatcher(m Matcher) *Selection {
  15. return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...)
  16. }
  17. // AddSelection adds the specified Selection object's nodes to those in the
  18. // current selection and returns a new Selection object.
  19. func (s *Selection) AddSelection(sel *Selection) *Selection {
  20. if sel == nil {
  21. return s.AddNodes()
  22. }
  23. return s.AddNodes(sel.Nodes...)
  24. }
  25. // Union is an alias for AddSelection.
  26. func (s *Selection) Union(sel *Selection) *Selection {
  27. return s.AddSelection(sel)
  28. }
  29. // AddNodes adds the specified nodes to those in the
  30. // current selection and returns a new Selection object.
  31. func (s *Selection) AddNodes(nodes ...*html.Node) *Selection {
  32. return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil))
  33. }
  34. // AndSelf adds the previous set of elements on the stack to the current set.
  35. // It returns a new Selection object containing the current Selection combined
  36. // with the previous one.
  37. func (s *Selection) AndSelf() *Selection {
  38. return s.AddSelection(s.prevSel)
  39. }