Skip to content

Commit 58a32db

Browse files
authored
Merge pull request #44 from moredure/patch-1
add `ExistsAttr` method
2 parents 44cd157 + 2ccb587 commit 58a32db

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

query.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ func SelectAttr(n *html.Node, name string) (val string) {
179179
return
180180
}
181181

182+
// ExistsAttr returns whether attribute with specified name exists.
183+
func ExistsAttr(n *html.Node, name string) bool {
184+
if n == nil {
185+
return false
186+
}
187+
for _, attr := range n.Attr {
188+
if attr.Key == name {
189+
return true
190+
}
191+
}
192+
return false
193+
}
194+
182195
// OutputHTML returns the text including tags name.
183196
func OutputHTML(n *html.Node, self bool) string {
184197
var buf bytes.Buffer

0 commit comments

Comments
 (0)