Ensure that it's safe to modify the DOM before doing so. Fixes #1...

...224.