[GopherJS] Insert CSS Dynamically


Insert (add, append) CSS to head element via GopherJS.

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

func appendCSSToHeadElement() {
      css := `.tooltip {
              position: absolute;
              left: -9999px;
              background-color: #CCFFFF;
              border-radius: 10px;
              font-family: Tahoma, Arial, serif;
              word-wrap: break-word;
      }`
      s := js.Global.Get("document").Call("createElement", "style")
      s.Set("innerHTML", css)
      // insert style of tooltip at the end of head element
      js.Global.Get("document").Call("getElementsByTagName", "head").Call("item", 0).Call("appendChild", s)
}

References:

[1]GopherJS - A compiler from Go to JavaScript (GitHub, GopherJS Playground, godoc)
[2]javascript insert css - Google search
[3][JavaScript] Load CSS Dynamically
[4]Load External JavaScript or CSS file Dynamically
[5][GopherJS] Set/Get DOM CSS