APCoding
APCoding

Reputation: 301

Javascript Ignoring Tags in document.write

Consider the following code:

document.write("a<b");

When I try to run that, it makes a outputs displaying the letter a. I think this is because it thinks that I want to start a tag, therefor excluding the rest. Is there a way to bypass this? A way to still display the <, and the rest of the line, too? It seems that the escape character, \, does not work (or am I doing something wrong?)

Thanks

Upvotes: 0

Views: 23

Answers (1)

Spencer Wieczorek
Spencer Wieczorek

Reputation: 21575

Yes it does think you are writing a tag for document.write(), instead use &lt;, as in less-than:

document.write("a&lt;b");

Upvotes: 2

Related Questions