Only change hidden attribute if it needs to
Use isNaN instead of comparing to NaN

Comparing to NaN always yields false in JavaScript.
Use textContent instead of innerHTML

Automatically escapes approriate characters to ensure no rogue HTML can
be added.