-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentattr.go
More file actions
32 lines (29 loc) · 825 Bytes
/
Copy pathdocumentattr.go
File metadata and controls
32 lines (29 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build wasm
package dom
// SetDocumentAttr sets an attribute on document.documentElement (<html>).
// value=="" removes the attribute — consistent with GetDocumentAttr returning ""
// for absent attributes.
func SetDocumentAttr(attr, value string) {
html := instance.(*domWasm).document.Get("documentElement")
if !html.Truthy() {
return
}
if value == "" {
html.Call("removeAttribute", attr)
} else {
html.Call("setAttribute", attr, value)
}
}
// GetDocumentAttr reads an attribute from document.documentElement.
// Returns "" if the attribute is absent.
func GetDocumentAttr(attr string) string {
html := instance.(*domWasm).document.Get("documentElement")
if !html.Truthy() {
return ""
}
v := html.Call("getAttribute", attr)
if v.IsNull() || v.IsUndefined() {
return ""
}
return v.String()
}