Documentation ¶
Overview ¶
Package goquery implements features similar to jQuery, including the chainable syntax, to manipulate and query an HTML document.
It brings a syntax and a set of features similar to jQuery to the Go language. It is based on Go's net/html package and the CSS Selector library cascadia. Since the net/html parser returns nodes, and not a full-featured DOM tree, jQuery's stateful manipulation functions (like height(), css(), detach()) have been left off.
Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. See the repository's wiki for various options on how to do this.
Syntax-wise, it is as close as possible to jQuery, with the same method names when possible, and that warm and fuzzy chainable interface. jQuery being the ultra-popular library that it is, writing a similar HTML-manipulating library was better to follow its API than to start anew (in the same spirit as Go's fmt package), even though some of its methods are less than intuitive (looking at you, index()...).
It is hosted on GitHub, along with additional documentation in the README.md file: https://github.com/puerkitobio/goquery
Please note that because of the net/html dependency, goquery requires Go1.1+.
The various methods are split into files based on the category of behavior. The three dots (...) indicate that various "overloads" are available.
* array.go : array-like positional manipulation of the selection.
- Eq()
- First()
- Get()
- Index...()
- Last()
- Slice()
* expand.go : methods that expand or augment the selection's set.
- Add...()
- AndSelf()
- Union(), which is an alias for AddSelection()
* filter.go : filtering methods, that reduce the selection's set.
- End()
- Filter...()
- Has...()
- Intersection(), which is an alias of FilterSelection()
- Not...()
* iteration.go : methods to loop over the selection's nodes.
- Each()
- EachWithBreak()
- Map()
* manipulation.go : methods for modifying the document
- After...()
- Append...()
- Before...()
- Clone()
- Empty()
- Prepend...()
- Remove...()
- ReplaceWith...()
- Unwrap()
- Wrap...()
- WrapAll...()
- WrapInner...()
* property.go : methods that inspect and get the node's properties values.
- Attr*(), RemoveAttr(), SetAttr()
- AddClass(), HasClass(), RemoveClass(), ToggleClass()
- Html()
- Length()
- Size(), which is an alias for Length()
- Text()
* query.go : methods that query, or reflect, a node's identity.
- Contains()
- Is...()
* traversal.go : methods to traverse the HTML document tree.
- Children...()
- Contents()
- Find...()
- Next...()
- Parent[s]...()
- Prev...()
- Siblings...()
* type.go : definition of the types exposed by goquery.
- Document
- Selection
- Matcher
* utilities.go : definition of helper functions (and not methods on a *Selection) that are not part of jQuery, but are useful to goquery.
- NodeName
- OuterHtml
Index ¶
- Constants
- func NodeName(s *Selection) string
- func OuterHtml(s *Selection) (string, error)
- func ValidImgURL(content, prefix string) error
- type Document
- type HtmlValidResult
- type Matcher
- type Selection
- func (s *Selection) Add(selector string) *Selection
- func (s *Selection) AddBack() *Selection
- func (s *Selection) AddBackFiltered(selector string) *Selection
- func (s *Selection) AddBackMatcher(m Matcher) *Selection
- func (s *Selection) AddClass(class ...string) *Selection
- func (s *Selection) AddMatcher(m Matcher) *Selection
- func (s *Selection) AddNodes(nodes ...*html.Node) *Selection
- func (s *Selection) AddSelection(sel *Selection) *Selection
- func (s *Selection) After(selector string) *Selection
- func (s *Selection) AfterHtml(html string) *Selection
- func (s *Selection) AfterMatcher(m Matcher) *Selection
- func (s *Selection) AfterNodes(ns ...*html.Node) *Selection
- func (s *Selection) AfterSelection(sel *Selection) *Selection
- func (s *Selection) AndSelf() *Selection
- func (s *Selection) Append(selector string) *Selection
- func (s *Selection) AppendHtml(html string) *Selection
- func (s *Selection) AppendMatcher(m Matcher) *Selection
- func (s *Selection) AppendNodes(ns ...*html.Node) *Selection
- func (s *Selection) AppendSelection(sel *Selection) *Selection
- func (s *Selection) Attr(attrName string) (val string, exists bool)
- func (s *Selection) AttrOr(attrName, defaultValue string) string
- func (s *Selection) Before(selector string) *Selection
- func (s *Selection) BeforeHtml(html string) *Selection
- func (s *Selection) BeforeMatcher(m Matcher) *Selection
- func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection
- func (s *Selection) BeforeSelection(sel *Selection) *Selection
- func (s *Selection) Children() *Selection
- func (s *Selection) ChildrenFiltered(selector string) *Selection
- func (s *Selection) ChildrenMatcher(m Matcher) *Selection
- func (s *Selection) Clone() *Selection
- func (s *Selection) Closest(selector string) *Selection
- func (s *Selection) ClosestMatcher(m Matcher) *Selection
- func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection
- func (s *Selection) ClosestSelection(sel *Selection) *Selection
- func (s *Selection) Contains(n *html.Node) bool
- func (s *Selection) Contents() *Selection
- func (s *Selection) ContentsFiltered(selector string) *Selection
- func (s *Selection) ContentsMatcher(m Matcher) *Selection
- func (s *Selection) Each(f func(int, *Selection)) *Selection
- func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection
- func (s *Selection) Empty() *Selection
- func (s *Selection) End() *Selection
- func (s *Selection) Eq(index int) *Selection
- func (s *Selection) Filter(selector string) *Selection
- func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection
- func (s *Selection) FilterMatcher(m Matcher) *Selection
- func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection
- func (s *Selection) FilterSelection(sel *Selection) *Selection
- func (s *Selection) Find(selector string) *Selection
- func (s *Selection) FindMatcher(m Matcher) *Selection
- func (s *Selection) FindNodes(nodes ...*html.Node) *Selection
- func (s *Selection) FindSelection(sel *Selection) *Selection
- func (s *Selection) First() *Selection
- func (s *Selection) Get(index int) *html.Node
- func (s *Selection) Has(selector string) *Selection
- func (s *Selection) HasClass(class string) bool
- func (s *Selection) HasMatcher(m Matcher) *Selection
- func (s *Selection) HasNodes(nodes ...*html.Node) *Selection
- func (s *Selection) HasSelection(sel *Selection) *Selection
- func (s *Selection) Html() (ret string, e error)
- func (s *Selection) Index() int
- func (s *Selection) IndexMatcher(m Matcher) int
- func (s *Selection) IndexOfNode(node *html.Node) int
- func (s *Selection) IndexOfSelection(sel *Selection) int
- func (s *Selection) IndexSelector(selector string) int
- func (s *Selection) Intersection(sel *Selection) *Selection
- func (s *Selection) Is(selector string) bool
- func (s *Selection) IsFunction(f func(int, *Selection) bool) bool
- func (s *Selection) IsMatcher(m Matcher) bool
- func (s *Selection) IsNodes(nodes ...*html.Node) bool
- func (s *Selection) IsSelection(sel *Selection) bool
- func (s *Selection) Last() *Selection
- func (s *Selection) Length() int
- func (s *Selection) Map(f func(int, *Selection) string) (result []string)
- func (s *Selection) Next() *Selection
- func (s *Selection) NextAll() *Selection
- func (s *Selection) NextAllFiltered(selector string) *Selection
- func (s *Selection) NextAllMatcher(m Matcher) *Selection
- func (s *Selection) NextFiltered(selector string) *Selection
- func (s *Selection) NextFilteredUntil(filterSelector, untilSelector string) *Selection
- func (s *Selection) NextFilteredUntilMatcher(filter, until Matcher) *Selection
- func (s *Selection) NextFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
- func (s *Selection) NextFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
- func (s *Selection) NextMatcher(m Matcher) *Selection
- func (s *Selection) NextMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
- func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
- func (s *Selection) NextUntil(selector string) *Selection
- func (s *Selection) NextUntilMatcher(m Matcher) *Selection
- func (s *Selection) NextUntilNodes(nodes ...*html.Node) *Selection
- func (s *Selection) NextUntilSelection(sel *Selection) *Selection
- func (s *Selection) Not(selector string) *Selection
- func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection
- func (s *Selection) NotMatcher(m Matcher) *Selection
- func (s *Selection) NotNodes(nodes ...*html.Node) *Selection
- func (s *Selection) NotSelection(sel *Selection) *Selection
- func (s *Selection) Parent() *Selection
- func (s *Selection) ParentFiltered(selector string) *Selection
- func (s *Selection) ParentMatcher(m Matcher) *Selection
- func (s *Selection) Parents() *Selection
- func (s *Selection) ParentsFiltered(selector string) *Selection
- func (s *Selection) ParentsFilteredUntil(filterSelector, untilSelector string) *Selection
- func (s *Selection) ParentsFilteredUntilMatcher(filter, until Matcher) *Selection
- func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
- func (s *Selection) ParentsFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
- func (s *Selection) ParentsMatcher(m Matcher) *Selection
- func (s *Selection) ParentsMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
- func (s *Selection) ParentsMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
- func (s *Selection) ParentsUntil(selector string) *Selection
- func (s *Selection) ParentsUntilMatcher(m Matcher) *Selection
- func (s *Selection) ParentsUntilNodes(nodes ...*html.Node) *Selection
- func (s *Selection) ParentsUntilSelection(sel *Selection) *Selection
- func (s *Selection) Prepend(selector string) *Selection
- func (s *Selection) PrependHtml(html string) *Selection
- func (s *Selection) PrependMatcher(m Matcher) *Selection
- func (s *Selection) PrependNodes(ns ...*html.Node) *Selection
- func (s *Selection) PrependSelection(sel *Selection) *Selection
- func (s *Selection) Prev() *Selection
- func (s *Selection) PrevAll() *Selection
- func (s *Selection) PrevAllFiltered(selector string) *Selection
- func (s *Selection) PrevAllMatcher(m Matcher) *Selection
- func (s *Selection) PrevFiltered(selector string) *Selection
- func (s *Selection) PrevFilteredUntil(filterSelector, untilSelector string) *Selection
- func (s *Selection) PrevFilteredUntilMatcher(filter, until Matcher) *Selection
- func (s *Selection) PrevFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
- func (s *Selection) PrevFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
- func (s *Selection) PrevMatcher(m Matcher) *Selection
- func (s *Selection) PrevMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
- func (s *Selection) PrevMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
- func (s *Selection) PrevUntil(selector string) *Selection
- func (s *Selection) PrevUntilMatcher(m Matcher) *Selection
- func (s *Selection) PrevUntilNodes(nodes ...*html.Node) *Selection
- func (s *Selection) PrevUntilSelection(sel *Selection) *Selection
- func (s *Selection) Remove() *Selection
- func (s *Selection) RemoveAttr(attrName string) *Selection
- func (s *Selection) RemoveClass(class ...string) *Selection
- func (s *Selection) RemoveFiltered(selector string) *Selection
- func (s *Selection) RemoveMatcher(m Matcher) *Selection
- func (s *Selection) ReplaceWith(selector string) *Selection
- func (s *Selection) ReplaceWithHtml(html string) *Selection
- func (s *Selection) ReplaceWithMatcher(m Matcher) *Selection
- func (s *Selection) ReplaceWithNodes(ns ...*html.Node) *Selection
- func (s *Selection) ReplaceWithSelection(sel *Selection) *Selection
- func (s *Selection) SetAttr(attrName, val string) *Selection
- func (s *Selection) SetHtml(html string) *Selection
- func (s *Selection) SetText(text string) *Selection
- func (s *Selection) Siblings() *Selection
- func (s *Selection) SiblingsFiltered(selector string) *Selection
- func (s *Selection) SiblingsMatcher(m Matcher) *Selection
- func (s *Selection) Size() int
- func (s *Selection) Slice(start, end int) *Selection
- func (s *Selection) Text() string
- func (s *Selection) ToggleClass(class ...string) *Selection
- func (s *Selection) Union(sel *Selection) *Selection
- func (s *Selection) Unwrap() *Selection
- func (s *Selection) Wrap(selector string) *Selection
- func (s *Selection) WrapAll(selector string) *Selection
- func (s *Selection) WrapAllHtml(html string) *Selection
- func (s *Selection) WrapAllMatcher(m Matcher) *Selection
- func (s *Selection) WrapAllNode(n *html.Node) *Selection
- func (s *Selection) WrapAllSelection(sel *Selection) *Selection
- func (s *Selection) WrapHtml(html string) *Selection
- func (s *Selection) WrapInner(selector string) *Selection
- func (s *Selection) WrapInnerHtml(html string) *Selection
- func (s *Selection) WrapInnerMatcher(m Matcher) *Selection
- func (s *Selection) WrapInnerNode(n *html.Node) *Selection
- func (s *Selection) WrapInnerSelection(sel *Selection) *Selection
- func (s *Selection) WrapMatcher(m Matcher) *Selection
- func (s *Selection) WrapNode(n *html.Node) *Selection
- func (s *Selection) WrapSelection(sel *Selection) *Selection
Constants ¶
const ( // ToEnd is a special index value that can be used as end index in a call // to Slice so that all elements are selected until the end of the Selection. // It is equivalent to passing (*Selection).Length(). ToEnd = maxInt )
Variables ¶
This section is empty.
Functions ¶
func NodeName ¶
NodeName returns the node name of the first element in the selection. It tries to behave in a similar way as the DOM's nodeName property (https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName).
Go's net/html package defines the following node types, listed with the corresponding returned value from this function:
ErrorNode : #error TextNode : #text DocumentNode : #document ElementNode : the element's tag name CommentNode : #comment DoctypeNode : the name of the document type
func OuterHtml ¶
OuterHtml returns the outer HTML rendering of the first item in the selection - that is, the HTML including the first element's tag and attributes.
Unlike InnerHtml, this is a function and not a method on the Selection, because this is not a jQuery method (in javascript-land, this is a property provided by the DOM).
func ValidImgURL ¶
Types ¶
type Document ¶
Document represents an HTML document to be manipulated. Unlike jQuery, which is loaded as part of a DOM document, and thus acts upon its containing document, GoQuery doesn't know which HTML document to act upon. So it needs to be told, and that's what the Document class is for. It holds the root document node to manipulate, and can make selections on this document.
func CloneDocument ¶
CloneDocument creates a deep-clone of a document.
func NewDocument
deprecated
NewDocument is a Document constructor that takes a string URL as argument. It loads the specified document, parses it, and stores the root Document node, ready to be manipulated.
Deprecated: Use the net/http standard library package to make the request and validate the response before calling goquery.NewDocumentFromReader with the response's body.
func NewDocumentFromNode ¶
NewDocumentFromNode is a Document constructor that takes a root html Node as argument.
func NewDocumentFromReader ¶
NewDocumentFromReader returns a Document from an io.Reader. It returns an error as second value if the reader's data cannot be parsed as html. It does not check if the reader is also an io.Closer, the provided reader is never closed by this call. It is the responsibility of the caller to close it if required.
func NewDocumentFromResponse
deprecated
NewDocumentFromResponse is another Document constructor that takes an http response as argument. It loads the specified response's document, parses it, and stores the root Document node, ready to be manipulated. The response's body is closed on return.
Deprecated: Use goquery.NewDocumentFromReader with the response's body.
type HtmlValidResult ¶
func ValidZxHtml ¶
func ValidZxHtml(htmlstr string) *HtmlValidResult
type Matcher ¶
type Matcher interface { Match(*html.Node) bool MatchAll(*html.Node) []*html.Node Filter([]*html.Node) []*html.Node }
Matcher is an interface that defines the methods to match HTML nodes against a compiled selector string. Cascadia's Selector implements this interface.
type Selection ¶
Selection represents a collection of nodes matching some criteria. The initial Selection can be created by using Document.Find, and then manipulated using the jQuery-like chainable syntax and methods.
func (*Selection) Add ¶
Add adds the selector string's matching nodes to those in the current selection and returns a new Selection object. The selector string is run in the context of the document of the current Selection object.
func (*Selection) AddBack ¶
AddBack adds the previous set of elements on the stack to the current set. It returns a new Selection object containing the current Selection combined with the previous one.
func (*Selection) AddBackFiltered ¶
AddBackFiltered reduces the previous set of elements on the stack to those that match the selector string, and adds them to the current set. It returns a new Selection object containing the current Selection combined with the filtered previous one
func (*Selection) AddBackMatcher ¶
AddBackMatcher reduces the previous set of elements on the stack to those that match the mateher, and adds them to the curernt set. It returns a new Selection object containing the current Selection combined with the filtered previous one
func (*Selection) AddClass ¶
AddClass adds the given class(es) to each element in the set of matched elements. Multiple class names can be specified, separated by a space or via multiple arguments.
func (*Selection) AddMatcher ¶
AddMatcher adds the matcher's matching nodes to those in the current selection and returns a new Selection object. The matcher is run in the context of the document of the current Selection object.
func (*Selection) AddNodes ¶
AddNodes adds the specified nodes to those in the current selection and returns a new Selection object.
func (*Selection) AddSelection ¶
AddSelection adds the specified Selection object's nodes to those in the current selection and returns a new Selection object.
func (*Selection) After ¶
After applies the selector from the root document and inserts the matched elements after the elements in the set of matched elements.
If one of the matched elements in the selection is not currently in the document, it's impossible to insert nodes after it, so it will be ignored.
This follows the same rules as Selection.Append.
func (*Selection) AfterHtml ¶
AfterHtml parses the html and inserts it after the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) AfterMatcher ¶
AfterMatcher applies the matcher from the root document and inserts the matched elements after the elements in the set of matched elements.
If one of the matched elements in the selection is not currently in the document, it's impossible to insert nodes after it, so it will be ignored.
This follows the same rules as Selection.Append.
func (*Selection) AfterNodes ¶
AfterNodes inserts the nodes after each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) AfterSelection ¶
AfterSelection inserts the elements in the selection after each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) AndSelf ¶
AndSelf adds the previous set of elements on the stack to the current set. It returns a new Selection object containing the current Selection combined with the previous one. Deprecated: This function has been deprecated and is now an alias for AddBack().
func (*Selection) Append ¶
Append appends the elements specified by the selector to the end of each element in the set of matched elements, following those rules:
1) The selector is applied to the root document.
2) Elements that are part of the document will be moved to the new location.
3) If there are multiple locations to append to, cloned nodes will be appended to all target locations except the last one, which will be moved as noted in (2).
func (*Selection) AppendHtml ¶
AppendHtml parses the html and appends it to the set of matched elements.
func (*Selection) AppendMatcher ¶
AppendMatcher appends the elements specified by the matcher to the end of each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) AppendNodes ¶
AppendNodes appends the specified nodes to each node in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) AppendSelection ¶
AppendSelection appends the elements in the selection to the end of each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) Attr ¶
Attr gets the specified attribute's value for the first element in the Selection. To get the value for each element individually, use a looping construct such as Each or Map method.
func (*Selection) AttrOr ¶
AttrOr works like Attr but returns default value if attribute is not present.
func (*Selection) Before ¶
Before inserts the matched elements before each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) BeforeHtml ¶
BeforeHtml parses the html and inserts it before the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) BeforeMatcher ¶
BeforeMatcher inserts the matched elements before each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) BeforeNodes ¶
BeforeNodes inserts the nodes before each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) BeforeSelection ¶
BeforeSelection inserts the elements in the selection before each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) Children ¶
Children gets the child elements of each element in the Selection. It returns a new Selection object containing these elements.
func (*Selection) ChildrenFiltered ¶
ChildrenFiltered gets the child elements of each element in the Selection, filtered by the specified selector. It returns a new Selection object containing these elements.
func (*Selection) ChildrenMatcher ¶
ChildrenMatcher gets the child elements of each element in the Selection, filtered by the specified matcher. It returns a new Selection object containing these elements.
func (*Selection) Clone ¶
Clone creates a deep copy of the set of matched nodes. The new nodes will not be attached to the document.
func (*Selection) Closest ¶
Closest gets the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
func (*Selection) ClosestMatcher ¶
ClosestMatcher gets the first element that matches the matcher by testing the element itself and traversing up through its ancestors in the DOM tree.
func (*Selection) ClosestNodes ¶
ClosestNodes gets the first element that matches one of the nodes by testing the element itself and traversing up through its ancestors in the DOM tree.
func (*Selection) ClosestSelection ¶
ClosestSelection gets the first element that matches one of the nodes in the Selection by testing the element itself and traversing up through its ancestors in the DOM tree.
func (*Selection) Contains ¶
Contains returns true if the specified Node is within, at any depth, one of the nodes in the Selection object. It is NOT inclusive, to behave like jQuery's implementation, and unlike Javascript's .contains, so if the contained node is itself in the selection, it returns false.
func (*Selection) Contents ¶
Contents gets the children of each element in the Selection, including text and comment nodes. It returns a new Selection object containing these elements.
func (*Selection) ContentsFiltered ¶
ContentsFiltered gets the children of each element in the Selection, filtered by the specified selector. It returns a new Selection object containing these elements. Since selectors only act on Element nodes, this function is an alias to ChildrenFiltered unless the selector is empty, in which case it is an alias to Contents.
func (*Selection) ContentsMatcher ¶
ContentsMatcher gets the children of each element in the Selection, filtered by the specified matcher. It returns a new Selection object containing these elements. Since matchers only act on Element nodes, this function is an alias to ChildrenMatcher.
func (*Selection) Each ¶
Each iterates over a Selection object, executing a function for each matched element. It returns the current Selection object. The function f is called for each element in the selection with the index of the element in that selection starting at 0, and a *Selection that contains only that element.
func (*Selection) EachWithBreak ¶
EachWithBreak iterates over a Selection object, executing a function for each matched element. It is identical to Each except that it is possible to break out of the loop by returning false in the callback function. It returns the current Selection object.
func (*Selection) Empty ¶
Empty removes all children nodes from the set of matched elements. It returns the children nodes in a new Selection.
func (*Selection) End ¶
End ends the most recent filtering operation in the current chain and returns the set of matched elements to its previous state.
func (*Selection) Eq ¶
Eq reduces the set of matched elements to the one at the specified index. If a negative index is given, it counts backwards starting at the end of the set. It returns a new Selection object, and an empty Selection object if the index is invalid.
func (*Selection) Filter ¶
Filter reduces the set of matched elements to those that match the selector string. It returns a new Selection object for this subset of matching elements.
func (*Selection) FilterFunction ¶
FilterFunction reduces the set of matched elements to those that pass the function's test. It returns a new Selection object for this subset of elements.
func (*Selection) FilterMatcher ¶
FilterMatcher reduces the set of matched elements to those that match the given matcher. It returns a new Selection object for this subset of matching elements.
func (*Selection) FilterNodes ¶
FilterNodes reduces the set of matched elements to those that match the specified nodes. It returns a new Selection object for this subset of elements.
func (*Selection) FilterSelection ¶
FilterSelection reduces the set of matched elements to those that match a node in the specified Selection object. It returns a new Selection object for this subset of elements.
func (*Selection) Find ¶
Find gets the descendants of each element in the current set of matched elements, filtered by a selector. It returns a new Selection object containing these matched elements.
func (*Selection) FindMatcher ¶
FindMatcher gets the descendants of each element in the current set of matched elements, filtered by the matcher. It returns a new Selection object containing these matched elements.
func (*Selection) FindNodes ¶
FindNodes gets the descendants of each element in the current Selection, filtered by some nodes. It returns a new Selection object containing these matched elements.
func (*Selection) FindSelection ¶
FindSelection gets the descendants of each element in the current Selection, filtered by a Selection. It returns a new Selection object containing these matched elements.
func (*Selection) First ¶
First reduces the set of matched elements to the first in the set. It returns a new Selection object, and an empty Selection object if the the selection is empty.
func (*Selection) Get ¶
Get retrieves the underlying node at the specified index. Get without parameter is not implemented, since the node array is available on the Selection object.
func (*Selection) Has ¶
Has reduces the set of matched elements to those that have a descendant that matches the selector. It returns a new Selection object with the matching elements.
func (*Selection) HasClass ¶
HasClass determines whether any of the matched elements are assigned the given class.
func (*Selection) HasMatcher ¶
HasMatcher reduces the set of matched elements to those that have a descendant that matches the matcher. It returns a new Selection object with the matching elements.
func (*Selection) HasNodes ¶
HasNodes reduces the set of matched elements to those that have a descendant that matches one of the nodes. It returns a new Selection object with the matching elements.
func (*Selection) HasSelection ¶
HasSelection reduces the set of matched elements to those that have a descendant that matches one of the nodes of the specified Selection object. It returns a new Selection object with the matching elements.
func (*Selection) Html ¶
Html gets the HTML contents of the first element in the set of matched elements. It includes text and comment nodes.
func (*Selection) Index ¶
Index returns the position of the first element within the Selection object relative to its sibling elements.
func (*Selection) IndexMatcher ¶
IndexMatcher returns the position of the first element within the Selection object relative to the elements matched by the matcher, or -1 if not found.
func (*Selection) IndexOfNode ¶
IndexOfNode returns the position of the specified node within the Selection object, or -1 if not found.
func (*Selection) IndexOfSelection ¶
IndexOfSelection returns the position of the first node in the specified Selection object within this Selection object, or -1 if not found.
func (*Selection) IndexSelector ¶
IndexSelector returns the position of the first element within the Selection object relative to the elements matched by the selector, or -1 if not found.
func (*Selection) Intersection ¶
Intersection is an alias for FilterSelection.
func (*Selection) Is ¶
Is checks the current matched set of elements against a selector and returns true if at least one of these elements matches.
func (*Selection) IsFunction ¶
IsFunction checks the current matched set of elements against a predicate and returns true if at least one of these elements matches.
func (*Selection) IsMatcher ¶
IsMatcher checks the current matched set of elements against a matcher and returns true if at least one of these elements matches.
func (*Selection) IsNodes ¶
IsNodes checks the current matched set of elements against the specified nodes and returns true if at least one of these elements matches.
func (*Selection) IsSelection ¶
IsSelection checks the current matched set of elements against a Selection object and returns true if at least one of these elements matches.
func (*Selection) Last ¶
Last reduces the set of matched elements to the last in the set. It returns a new Selection object, and an empty Selection object if the selection is empty.
func (*Selection) Map ¶
Map passes each element in the current matched set through a function, producing a slice of string holding the returned values. The function f is called for each element in the selection with the index of the element in that selection starting at 0, and a *Selection that contains only that element.
func (*Selection) Next ¶
Next gets the immediately following sibling of each element in the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) NextAll ¶
NextAll gets all the following siblings of each element in the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) NextAllFiltered ¶
NextAllFiltered gets all the following siblings of each element in the Selection filtered by a selector. It returns a new Selection object containing the matched elements.
func (*Selection) NextAllMatcher ¶
NextAllMatcher gets all the following siblings of each element in the Selection filtered by a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) NextFiltered ¶
NextFiltered gets the immediately following sibling of each element in the Selection filtered by a selector. It returns a new Selection object containing the matched elements.
func (*Selection) NextFilteredUntil ¶
NextFilteredUntil is like NextUntil, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) NextFilteredUntilMatcher ¶
NextFilteredUntilMatcher is like NextUntilMatcher, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) NextFilteredUntilNodes ¶
NextFilteredUntilNodes is like NextUntilNodes, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) NextFilteredUntilSelection ¶
NextFilteredUntilSelection is like NextUntilSelection, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) NextMatcher ¶
NextMatcher gets the immediately following sibling of each element in the Selection filtered by a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) NextMatcherUntilNodes ¶
NextMatcherUntilNodes is like NextUntilNodes, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) NextMatcherUntilSelection ¶
NextMatcherUntilSelection is like NextUntilSelection, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) NextUntil ¶
NextUntil gets all following siblings of each element up to but not including the element matched by the selector. It returns a new Selection object containing the matched elements.
func (*Selection) NextUntilMatcher ¶
NextUntilMatcher gets all following siblings of each element up to but not including the element matched by the matcher. It returns a new Selection object containing the matched elements.
func (*Selection) NextUntilNodes ¶
NextUntilNodes gets all following siblings of each element up to but not including the element matched by the nodes. It returns a new Selection object containing the matched elements.
func (*Selection) NextUntilSelection ¶
NextUntilSelection gets all following siblings of each element up to but not including the element matched by the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) Not ¶
Not removes elements from the Selection that match the selector string. It returns a new Selection object with the matching elements removed.
func (*Selection) NotFunction ¶
NotFunction removes elements from the Selection that pass the function's test. It returns a new Selection object with the matching elements removed.
func (*Selection) NotMatcher ¶
NotMatcher removes elements from the Selection that match the given matcher. It returns a new Selection object with the matching elements removed.
func (*Selection) NotNodes ¶
NotNodes removes elements from the Selection that match the specified nodes. It returns a new Selection object with the matching elements removed.
func (*Selection) NotSelection ¶
NotSelection removes elements from the Selection that match a node in the specified Selection object. It returns a new Selection object with the matching elements removed.
func (*Selection) Parent ¶
Parent gets the parent of each element in the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) ParentFiltered ¶
ParentFiltered gets the parent of each element in the Selection filtered by a selector. It returns a new Selection object containing the matched elements.
func (*Selection) ParentMatcher ¶
ParentMatcher gets the parent of each element in the Selection filtered by a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) Parents ¶
Parents gets the ancestors of each element in the current Selection. It returns a new Selection object with the matched elements.
func (*Selection) ParentsFiltered ¶
ParentsFiltered gets the ancestors of each element in the current Selection. It returns a new Selection object with the matched elements.
func (*Selection) ParentsFilteredUntil ¶
ParentsFilteredUntil is like ParentsUntil, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsFilteredUntilMatcher ¶
ParentsFilteredUntilMatcher is like ParentsUntilMatcher, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsFilteredUntilNodes ¶
func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
ParentsFilteredUntilNodes is like ParentsUntilNodes, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsFilteredUntilSelection ¶
ParentsFilteredUntilSelection is like ParentsUntilSelection, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsMatcher ¶
ParentsMatcher gets the ancestors of each element in the current Selection. It returns a new Selection object with the matched elements.
func (*Selection) ParentsMatcherUntilNodes ¶
ParentsMatcherUntilNodes is like ParentsUntilNodes, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsMatcherUntilSelection ¶
ParentsMatcherUntilSelection is like ParentsUntilSelection, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsUntil ¶
ParentsUntil gets the ancestors of each element in the Selection, up to but not including the element matched by the selector. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsUntilMatcher ¶
ParentsUntilMatcher gets the ancestors of each element in the Selection, up to but not including the element matched by the matcher. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsUntilNodes ¶
ParentsUntilNodes gets the ancestors of each element in the Selection, up to but not including the specified nodes. It returns a new Selection object containing the matched elements.
func (*Selection) ParentsUntilSelection ¶
ParentsUntilSelection gets the ancestors of each element in the Selection, up to but not including the elements in the specified Selection. It returns a new Selection object containing the matched elements.
func (*Selection) Prepend ¶
Prepend prepends the elements specified by the selector to each element in the set of matched elements, following the same rules as Append.
func (*Selection) PrependHtml ¶
PrependHtml parses the html and prepends it to the set of matched elements.
func (*Selection) PrependMatcher ¶
PrependMatcher prepends the elements specified by the matcher to each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) PrependNodes ¶
PrependNodes prepends the specified nodes to each node in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) PrependSelection ¶
PrependSelection prepends the elements in the selection to each element in the set of matched elements.
This follows the same rules as Selection.Append.
func (*Selection) Prev ¶
Prev gets the immediately preceding sibling of each element in the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) PrevAll ¶
PrevAll gets all the preceding siblings of each element in the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) PrevAllFiltered ¶
PrevAllFiltered gets all the preceding siblings of each element in the Selection filtered by a selector. It returns a new Selection object containing the matched elements.
func (*Selection) PrevAllMatcher ¶
PrevAllMatcher gets all the preceding siblings of each element in the Selection filtered by a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) PrevFiltered ¶
PrevFiltered gets the immediately preceding sibling of each element in the Selection filtered by a selector. It returns a new Selection object containing the matched elements.
func (*Selection) PrevFilteredUntil ¶
PrevFilteredUntil is like PrevUntil, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) PrevFilteredUntilMatcher ¶
PrevFilteredUntilMatcher is like PrevUntilMatcher, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) PrevFilteredUntilNodes ¶
PrevFilteredUntilNodes is like PrevUntilNodes, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) PrevFilteredUntilSelection ¶
PrevFilteredUntilSelection is like PrevUntilSelection, with the option to filter the results based on a selector string. It returns a new Selection object containing the matched elements.
func (*Selection) PrevMatcher ¶
PrevMatcher gets the immediately preceding sibling of each element in the Selection filtered by a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) PrevMatcherUntilNodes ¶
PrevMatcherUntilNodes is like PrevUntilNodes, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) PrevMatcherUntilSelection ¶
PrevMatcherUntilSelection is like PrevUntilSelection, with the option to filter the results based on a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) PrevUntil ¶
PrevUntil gets all preceding siblings of each element up to but not including the element matched by the selector. It returns a new Selection object containing the matched elements.
func (*Selection) PrevUntilMatcher ¶
PrevUntilMatcher gets all preceding siblings of each element up to but not including the element matched by the matcher. It returns a new Selection object containing the matched elements.
func (*Selection) PrevUntilNodes ¶
PrevUntilNodes gets all preceding siblings of each element up to but not including the element matched by the nodes. It returns a new Selection object containing the matched elements.
func (*Selection) PrevUntilSelection ¶
PrevUntilSelection gets all preceding siblings of each element up to but not including the element matched by the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) Remove ¶
Remove removes the set of matched elements from the document. It returns the same selection, now consisting of nodes not in the document.
func (*Selection) RemoveAttr ¶
RemoveAttr removes the named attribute from each element in the set of matched elements.
func (*Selection) RemoveClass ¶
RemoveClass removes the given class(es) from each element in the set of matched elements. Multiple class names can be specified, separated by a space or via multiple arguments. If no class name is provided, all classes are removed.
func (*Selection) RemoveFiltered ¶
RemoveFiltered removes the set of matched elements by selector. It returns the Selection of removed nodes.
func (*Selection) RemoveMatcher ¶
RemoveMatcher removes the set of matched elements. It returns the Selection of removed nodes.
func (*Selection) ReplaceWith ¶
ReplaceWith replaces each element in the set of matched elements with the nodes matched by the given selector. It returns the removed elements.
This follows the same rules as Selection.Append.
func (*Selection) ReplaceWithHtml ¶
ReplaceWithHtml replaces each element in the set of matched elements with the parsed HTML. It returns the removed elements.
This follows the same rules as Selection.Append.
func (*Selection) ReplaceWithMatcher ¶
ReplaceWithMatcher replaces each element in the set of matched elements with the nodes matched by the given Matcher. It returns the removed elements.
This follows the same rules as Selection.Append.
func (*Selection) ReplaceWithNodes ¶
ReplaceWithNodes replaces each element in the set of matched elements with the given nodes. It returns the removed elements.
This follows the same rules as Selection.Append.
func (*Selection) ReplaceWithSelection ¶
ReplaceWithSelection replaces each element in the set of matched elements with the nodes from the given Selection. It returns the removed elements.
This follows the same rules as Selection.Append.
func (*Selection) SetAttr ¶
SetAttr sets the given attribute on each element in the set of matched elements.
func (*Selection) SetHtml ¶
SetHtml sets the html content of each element in the selection to specified html string.
func (*Selection) SetText ¶
SetText sets the content of each element in the selection to specified content. The provided text string is escaped.
func (*Selection) Siblings ¶
Siblings gets the siblings of each element in the Selection. It returns a new Selection object containing the matched elements.
func (*Selection) SiblingsFiltered ¶
SiblingsFiltered gets the siblings of each element in the Selection filtered by a selector. It returns a new Selection object containing the matched elements.
func (*Selection) SiblingsMatcher ¶
SiblingsMatcher gets the siblings of each element in the Selection filtered by a matcher. It returns a new Selection object containing the matched elements.
func (*Selection) Slice ¶
Slice reduces the set of matched elements to a subset specified by a range of indices. The start index is 0-based and indicates the index of the first element to select. The end index is 0-based and indicates the index at which the elements stop being selected (the end index is not selected).
The indices may be negative, in which case they represent an offset from the end of the selection.
The special value ToEnd may be specified as end index, in which case all elements until the end are selected. This works both for a positive and negative start index.
func (*Selection) Text ¶
Text gets the combined text contents of each element in the set of matched elements, including their descendants.
func (*Selection) ToggleClass ¶
ToggleClass adds or removes the given class(es) for each element in the set of matched elements. Multiple class names can be specified, separated by a space or via multiple arguments.
func (*Selection) Unwrap ¶
Unwrap removes the parents of the set of matched elements, leaving the matched elements (and their siblings, if any) in their place. It returns the original selection.
func (*Selection) Wrap ¶
Wrap wraps each element in the set of matched elements inside the first element matched by the given selector. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapAll ¶
WrapAll wraps a single HTML structure, matched by the given selector, around all elements in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapAllHtml ¶
WrapAllHtml wraps the given HTML structure around all elements in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapAllMatcher ¶
WrapAllMatcher wraps a single HTML structure, matched by the given Matcher, around all elements in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapAllNode ¶
WrapAllNode wraps the given node around the first element in the Selection, making all other nodes in the Selection children of the given node. The node is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapAllSelection ¶
WrapAllSelection wraps a single HTML structure, the first node of the given Selection, around all elements in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapHtml ¶
WrapHtml wraps each element in the set of matched elements inside the inner- most child of the given HTML.
It returns the original set of elements.
func (*Selection) WrapInner ¶
WrapInner wraps an HTML structure, matched by the given selector, around the content of element in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapInnerHtml ¶
WrapInnerHtml wraps an HTML structure, matched by the given selector, around the content of element in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapInnerMatcher ¶
WrapInnerMatcher wraps an HTML structure, matched by the given selector, around the content of element in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapInnerNode ¶
WrapInnerNode wraps an HTML structure, matched by the given selector, around the content of element in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapInnerSelection ¶
WrapInnerSelection wraps an HTML structure, matched by the given selector, around the content of element in the set of matched elements. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapMatcher ¶
WrapMatcher wraps each element in the set of matched elements inside the first element matched by the given matcher. The matched child is cloned before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapNode ¶
WrapNode wraps each element in the set of matched elements inside the inner- most child of the given node. The given node is copied before being inserted into the document.
It returns the original set of elements.
func (*Selection) WrapSelection ¶
WrapSelection wraps each element in the set of matched elements inside the first element in the given Selection. The element is cloned before being inserted into the document.
It returns the original set of elements.