Reputation: 85573
I found the following picture here
So, I want to know how JavaScript comment (//) checks for XHTML support?
Upvotes: 0
Views: 91
Reputation: 944170
They don't.
When the browser is parsing in HTML mode, the CDATA markers are treated as part of the script and passed to the JS engine. The comments therefore comment out the CDATA markers as they are invalid JavaScript. This stops the script from erroring.
In XML mode, the CDATA markers are treated as markup and are parsed before the result is passed to the JS engine. The comments therefore comment out empty lines and have no practical effect.
The //
are not for browsers that do not support XHTML but are for browsers that have been instructed to treat the XHTML as HTML.
Generally speaking, you should simply not use XHTML. It provides many complications (especially if you are trying to write HTML-Compatible XHTML) and few benefits (which most developers don't benefit from anyway).
Upvotes: 2