Include a real DOM implement in JS.

Builds on #134.

This is a pretty big change. Any thoughts @humphd?