[GopherJS] Replace DOM Element in Place


Replace DOM element in place via GopherJS.

Question

Replace element of id foo with another element of id foo2

Answer

import "github.com/gopherjs/gopherjs/js"

element := js.Global.Get("document").Call("getElementById", "foo")
element2 := js.Global.Get("document").Call("getElementById", "foo2")
element.Get("parentNode").Call("replaceChild", element2, element)

See [3] for more information.


References:

[1]GopherJS - A compiler from Go to JavaScript (GitHub, GopherJS Playground, godoc)
[2]
[3]How to replace DOM element in place using Javascript? - Stack Overflow