
12

[Golang] querySelectorAll and querySelector Example by GopherJS
source link: http://siongui.github.io/2016/02/14/go-querySelectorAll-querySelector-by-gopherjs/
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.

Golang querySelectorAll and querySelector Example by GopherJS.
querySelector
The querySelector() method returns a DOM element object:
// document object d := js.Global.Get("document") // return element whose css class is setting-menu element := d.Call("querySelector", ".setting-menu") // do something with the element ...
querySelectorAll
The querySelectorAll() method returns a NodeList:
// document object d := js.Global.Get("document") // return a nodelist in which the elements whose css class are about-link nodeList := d.Call("querySelectorAll", ".about-link") // access individual element length := nodeList.Get("length").Int() for i := 0; i < length; i++ { // get i-th element in nodelist element := nodeList.Call("item", i) // do something with the element ... }
Tested on: Ubuntu Linux 15.10, Go 1.5.3.
References:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK