State machines in the DOM