-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdocument.go
42 lines (31 loc) · 975 Bytes
/
document.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
41
42
package tinydom
import "syscall/js"
// Document wraps the JavaScript document element, which is usually fetched by js.Global().Get("document")
type Document struct {
js.Value
}
var doc = js.Global().Get("document")
func GetDocument() *Document {
return &Document{doc}
}
func (e *Document) ActiveElement() *Element {
return &Element{e.Get("activeElement")}
}
func (e *Document) DocumentElement() *Element {
return &Element{e.Get("documentElement")}
}
func (d *Document) CreateElement(tag string) *Element {
return &Element{d.Call("createElement", tag)}
}
func (d *Document) CreateTextNode(textContent string) *Element {
return &Element{d.Call("createTextNode", textContent)}
}
func (d *Document) CreateDocumentFragment() *Element {
return &Element{d.Call("createDocumentFragment")}
}
func (d *Document) GetElementById(id string) *Element {
return &Element{d.Call("getElementById", id)}
}
func (d *Document) Write(markup string) {
d.Call("write", markup)
}