3

[GopherJS] Insert CSS Dynamically

 2 years ago
source link: http://siongui.github.io/2016/06/04/gopherjs-add-css-dynamically/
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.
neoserver,ios ssh client

[GopherJS] Insert CSS Dynamically

June 04, 2016

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)
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK