gopherjs - style/style.go
1 // Package style implements a simple way to handle styling in an HTML document
2 package style // import "vimagination.zapto.org/gopherjs/style"
3
4 import (
5 "honnef.co/go/js/dom"
6 "vimagination.zapto.org/gopherjs/xdom"
7 "vimagination.zapto.org/gopherjs/xjs"
8 )
9
10 // Add adds the given CSS string to the DOM
11 func Add(css string) dom.Element {
12 h := dom.GetWindow().Document().GetElementsByTagName("head")
13 if len(h) == 0 {
14 return nil
15 }
16 s := xdom.Style()
17 h[0].AppendChild(xjs.SetInnerText(s, css))
18 return s
19 }