O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting a DOM element by ID

We can use the document object's getElementById method to access an element for a given id. In these examples, we access the primary content div container, which has id of "primaryContent".

JavaScript

element = document.getElementById("primaryContent");

GopherJS

element := js.Global.Get("document").Call("getElementById", "primaryContent")

DOM Binding

element := dom.GetWindow().Document().GetElementByID("primaryContent")

Although the dom package's method calls are very similar to the JavaScript method calls, subtle differences can occur.

For example, take note of the capitalization in the getElementById method call on the document object using JavaScript, and compare it with the capitalization of the GetElementByID ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required