-
Notifications
You must be signed in to change notification settings - Fork 58
/
document.go
64 lines (58 loc) · 1.21 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package dom
import "github.com/dennwc/dom/js"
func GetDocument() *Document {
doc := js.Get("document")
if !doc.Valid() {
return nil
}
return &Document{NodeBase{v: doc}}
}
func NewElement(tag string) *Element {
return Doc.CreateElement(tag)
}
var _ Node = (*Document)(nil)
type Document struct {
NodeBase
}
func (d *Document) CreateElement(tag string) *Element {
if d == nil {
return nil
}
v := d.v.Call("createElement", tag)
return AsElement(v)
}
func (d *Document) CreateElementNS(ns string, tag string) *Element {
if d == nil {
return nil
}
v := d.v.Call("createElementNS", ns, tag)
return AsElement(v)
}
func (d *Document) GetElementById(id string) *Element {
if d == nil {
return nil
}
v := d.v.Call("getElementById", id)
return AsElement(v)
}
func (d *Document) GetElementsByTagName(tag string) NodeList {
if d == nil {
return nil
}
v := d.v.Call("getElementsByTagName", tag)
return AsNodeList(v)
}
func (d *Document) QuerySelector(qu string) *Element {
if d == nil {
return nil
}
v := d.v.Call("querySelector", qu)
return AsElement(v)
}
func (d *Document) QuerySelectorAll(qu string) NodeList {
if d == nil {
return nil
}
v := d.v.Call("querySelectorAll", qu)
return AsNodeList(v)
}