Re: HTML Comment In Script Elements

Kravvitz wrote:

> Is it intentional that the HTML Validator doesn't give an error
> message when an HTML comment is started in a <script> element but the
> end of it is missing in an HTML document?

There are no HTML comments inside a <script> element, since the content 
model is CDATA, which means that no markup is recognized, except for end 
tags. Thus, from the viewpoint of HTML syntax, "<!--" inside a <script> 
element is just character data.

> It does show error messages
> as a result of this error in XHTML documents.

In XHTML, the content model is #PCDATA, which means that markup is 
recognized.

In practice, "<!--" inside a <script> element is risky in XHTML 
documents, since when the document is processed genuinely as XHTML, the 
browser or other processor _may_ remove comments before any other 
processing, but is not required to. And when processed as classic HTML, 
which is the only way to make XHTML digestible to IE, such "comments" 
are not removed but passed to the script language processor.

Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/ 

Received on Monday, 12 May 2008 05:51:30 UTC