HTML entity escape (Pitfall)

It looks like HTML but it isn't intended to be.

You can sometimes innocently include some text into your script that when presented with adocument.write() gets completely misunderstood by the HTML parser. This will almost certainly be due to the presence of "<" and ">" characters in the output. It is likely that the browser will see what it thinks is a tag, but then ignore it according to the "I don't know what it is - so I won't display it" rule, as it won't be a recognized tag.

Use HTML escapes to output the character as intended.

This is important for the following characters if not for others:

< becomes &lt;

> becomes &gt;

& becomes &amp;

See also:Pitfalls


Wrox Instant JavaScript - page - 46