forked from dennwc/dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.go
46 lines (40 loc) · 1.03 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
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 {
v := d.v.Call("createElement", tag)
return AsElement(v)
}
func (d *Document) CreateElementNS(ns string, tag string) *Element {
v := d.v.Call("createElementNS", ns, tag)
return AsElement(v)
}
func (d *Document) GetElementById(id string) *Element {
v := d.v.Call("getElementById", id)
return AsElement(v)
}
func (d *Document) GetElementsByTagName(tag string) NodeList {
v := d.v.Call("getElementsByTagName", tag)
return AsNodeList(v)
}
func (d *Document) QuerySelector(qu string) *Element {
v := d.v.Call("querySelector", qu)
return AsElement(v)
}
func (d *Document) QuerySelectorAll(qu string) NodeList {
v := d.v.Call("querySelectorAll", qu)
return AsNodeList(v)
}