Documentation ¶
Overview ¶
Package wasm aims to make DOM manipulation in Go as similar to JavaScript as possible. The Go code is compiled to WebAssembly via official Go compiler 1.11 or later. This package is used for front-end programming.
You can import wasm as follows:
import ( . "github.com/siongui/godom/wasm" )
Access dom element with id="foo" as follows:
foo := Document.GetElementById("foo")
Or
foo := Document.QuerySelector("#foo")
If something is not implemented in this library, you can use methods of js.Value in "syscall/js" to manipulate DOM API directly.
For example, if **textContent** property of foo is not implemented, you can use Get method of js.Value in "syscall/js" to get the **textContent** property as follows:
t := foo.Get("textContent").String()
If some DOM method is not implemented, you can use Call method provided by js.Value in "syscall/js". For example, if foo is an audio element and **play** method of foo is not implemented. You can use Call method of js.Value in "syscall/js" to call **play** method of DOM audio element directly.
foo.Call("play")
You can also read the godoc of "syscall/js":
https://tip.golang.org/pkg/syscall/js/ https://godoc.org/syscall/js
Index ¶
- Variables
- func Alert(s string)
- type DOMRect
- type DOMTokenList
- type Value
- func (v Value) ActiveElement() Value
- func (v Value) ClassList() DOMTokenList
- func (v Value) CreateElement(tag string) Value
- func (v Value) CreateTextNode(textContent string) Value
- func (v Value) GetAttribute(attributeName string) string
- func (v Value) GetBoundingClientRect() DOMRect
- func (v Value) GetElementById(id string) Value
- func (v Value) InnerHTML() string
- func (v Value) OuterHTML() string
- func (v Value) QuerySelector(selectors string) Value
- func (v Value) QuerySelectorAll(selectors string) []Value
- func (v Value) SetInnerHTML(html string)
- func (v Value) SetOuterHTML(html string)
- func (v Value) TagName() string
- func (v Value) Write(markup string)
Constants ¶
This section is empty.
Variables ¶
var Document = Value{js.Global().Get("document")}
equivalent to document object in JavaScript DOM API.
var Window = &window{js.Global()}
equivalent to window object in JavaScript DOM API.
Functions ¶
Types ¶
type DOMTokenList ¶
func (DOMTokenList) Add ¶
func (t DOMTokenList) Add(s string)
func (DOMTokenList) Contains ¶
func (t DOMTokenList) Contains(s string) bool
func (DOMTokenList) Length ¶
func (t DOMTokenList) Length() int
func (DOMTokenList) Remove ¶
func (t DOMTokenList) Remove(s string)
func (DOMTokenList) Toggle ¶
func (t DOMTokenList) Toggle(s string)
type Value ¶
This type usually represents a DOM element or node. The type is actually a wrapper for js.Value in syscall/js package. Any instance of the type can also use the methods provided by syscall/js, such as Call, Get, and Set methods. If something is not implemented in this library, you can use the methods provided by syscall/js to manipulate JavaScript DOM API directly.
func (Value) ActiveElement ¶
Returns the currently focused element https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
func (Value) ClassList ¶
func (v Value) ClassList() DOMTokenList
func (Value) CreateElement ¶
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
func (Value) CreateTextNode ¶
https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode
func (Value) GetBoundingClientRect ¶
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
func (Value) GetElementById ¶
https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
func (Value) QuerySelectorAll ¶
https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll