Skip to content

Commit

Permalink
Merge pull request #44 from moredure/patch-1
Browse files Browse the repository at this point in the history
add `ExistsAttr` method
  • Loading branch information
zhengchun authored Aug 21, 2021
2 parents 44cd157 + 2ccb587 commit 58a32db
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ func SelectAttr(n *html.Node, name string) (val string) {
return
}

// ExistsAttr returns whether attribute with specified name exists.
func ExistsAttr(n *html.Node, name string) bool {
if n == nil {
return false
}
for _, attr := range n.Attr {
if attr.Key == name {
return true
}
}
return false
}

// OutputHTML returns the text including tags name.
func OutputHTML(n *html.Node, self bool) string {
var buf bytes.Buffer
Expand Down

0 comments on commit 58a32db

Please sign in to comment.