-
Notifications
You must be signed in to change notification settings - Fork 13
/
dom.go
40 lines (32 loc) · 818 Bytes
/
dom.go
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
33
34
35
36
37
38
39
40
package dom
import (
"fmt"
"syscall/js"
)
func GetDocument() js.Value {
return js.Global().Get("document")
}
func CreateElement(tag string) js.Value {
document := GetDocument()
return document.Call("createElement", tag)
}
func GetElementByID(id string) js.Value {
document := GetDocument()
return document.Call("getElementById", id)
}
func AppendChild(parent js.Value, child js.Value) {
parent.Call("appendChild", child)
}
func SetInnerHTML(object js.Value, value interface{}) {
object.Set("innerHTML", value)
}
func AddTd(tr js.Value, value interface{}) {
td := CreateElement("td")
SetInnerHTML(td, value)
AppendChild(tr, td)
}
func AddTdf(tr js.Value, formatString string, value interface{}) {
td := CreateElement("td")
SetInnerHTML(td, fmt.Sprintf(formatString, value))
AppendChild(tr, td)
}