[Golang] Remove All Child Nodes of a DOM Element by GopherJS
In JavaScript, we can remove all child nodes of a DOM element [4] by:
while (elm.hasChildNodes()) {
elm.removeChild(elm.lastChild);
}
In Golang, we can do the same by GopherJS:
import "github.com/gopherjs/gopherjs/js"
for elm.Call("hasChildNodes").Bool() {
elm.Call("removeChild", elm.Get("lastChild"))
}
Tested on: Ubuntu Linux 15.10, Go 1.5.3, Chromium Version 48.0.2564.82 Ubuntu 15.10 (64-bit).
References:
[1] | GopherJS - A compiler from Go to JavaScript (GitHub, GopherJS Playground, ) |
[2] | Bindings · gopherjs/gopherjs Wiki · GitHub |
[3] | dom - GopherJS bindings for the JavaScript DOM APIs (GitHub) |
[4] | JavaScript Remove All Children of a DOM Element |