title: How can I access DOM Element properties from Go WebAssembly?
body: <p>I'm trying to extend the "Hello WebAssembly" example from <a href="https://github.com/golang/go/wiki/WebAssembly" rel="nofollow noreferrer">https://github.com/golang/go/wiki/WebAssembly</a>. As given, the example simply prints a message to the console. I wanted to add some code using <code>syscall/js</code> to replace the body element content.</p>
  
  <p>The attempt below fails to build:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  
      "syscall/js"
  )
  
  func main() {
      fmt.Println("Hello, WebAssembly!") // original example
      // I added
      doc := js.Global().Get("document")
      body := doc.Call("getElementById", "thebody")
      body.innerHTML = "Dynamic Content"
  }
  </code></pre>
  
  <p>When I try to build with <code>$ env GOOS=js GOARCH=wasm go build -o main.wasm</code>
  I get :
  <code>
  ./wasm.go:14:6: body.innerHTML undefined (type js.Value has no field or method innerHTML)
  </code></p>
  
  <p>Not surprising when you think about it, but I don't see an example in the doc at <a href="https://godoc.org/syscall/js" rel="nofollow noreferrer">https://godoc.org/syscall/js</a> that explains how to get and set element properties.</p>