feat: Add Node#QuerySelectorAll
This commit is contained in:
parent
91fb097308
commit
3a2cfbb8be
1 changed files with 14 additions and 0 deletions
14
html.go
14
html.go
|
@ -30,6 +30,20 @@ func (n *Node) QuerySelector(selector string) *Node {
|
|||
return n.GetElementByTagName(selector)
|
||||
}
|
||||
|
||||
func (n *Node) QuerySelectorAll(selector string) []*Node {
|
||||
return n.FindMany(func(n *Node) bool {
|
||||
if strings.HasPrefix(selector, "#") {
|
||||
return n.HasAttr("id", selector[1:])
|
||||
}
|
||||
|
||||
if strings.HasPrefix(selector, ".") {
|
||||
return n.HasClass(selector[1:])
|
||||
}
|
||||
|
||||
return n.Type == html.ElementNode && n.Data == selector
|
||||
})
|
||||
}
|
||||
|
||||
func (n *Node) GetElementById(id string) *Node {
|
||||
return n.FindOne(func(n *Node) bool {
|
||||
return n.HasAttr("id", id)
|
||||
|
|
Loading…
Reference in a new issue