liveBook · Manning

Document Object Model

As explained in Learn Go with Pocket-Sized Projects

The DOM, or Document Object Model, is a programming interface representing an HTML or XML document as an object tree that scripts can inspect and modify.

The Document Object Model (DOM) gives Go code a way to inspect and modify an HTML page. In a WebAssembly application, Go retrieves the document, finds elements by ID, and updates their properties. section 12.2 section 12.2.1

A Go program can use the DOM to:

  • Find an element with document.Call("getElementById", id). section 12.2.1
  • Change displayed content by setting the element's innerHTML property. section 12.2.1
  • Read form input through an argument passed from JavaScript or through the element's value property. section 12.2.3

Multiplication quiz

An HTML page provides spans with operand1 and operand2 IDs plus a numeric answer field. Go generates operands, writes them into the spans, reads the submitted answer, and generates a new exercise after a correct result. section 12.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains element lookup, property reads and writes, callbacks, validation, and input resetting, while deferring broader browser internals.
Examples
Demonstrates operand spans, numeric form input, alert feedback, answer validation, and generated multiplication exercises.
What it assumes
Assumes Go and HTML familiarity while introducing browser-side DOM access through syscall/js.
What you can do after
Build interactive browser pages by reading and changing HTML elements from Go through WebAssembly.
How it connects
Connects the DOM with HTML, JavaScript, WebAssembly, forms, event callbacks, and the syscall/js package.

Also explained in

Compare how 8 books explain Document Object Model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.