7

[GopherJS] createElement and createTextNode DOM Example

 2 years ago
source link: http://siongui.github.io/2016/12/30/gopherjs-createElement-createTextNode-dom-example/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[GopherJS] createElement and createTextNode DOM Example

December 30, 2016

DOM Example of createElement and createTextNode via GopherJS.

The following code creates DOM equivalent to <div><span>Hello</span> World!</div>.

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

func createElementAndTextNode() *js.Object {
      div := js.Global.Get("document").Call("createElement", "div")

      span := js.Global.Get("document").Call("createElement", "span")
      span.Set("textContent", "Hello")
      div.Call("appendChild", span)

      text := js.Global.Get("document").Call("createTextNode", " World!")
      div.Call("appendChild", text)

      return div
}

Tested on:

  • Ubuntu Linux 16.10
  • Go 1.7.4
  • Chromium Version 55.0.2883.87 Built on Ubuntu , running on Ubuntu 16.10 (64-bit)

References:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK