W3C home > Mailing lists > Public > www-validator@w3.org > February 2008

Re: document type does not allow element "style" here

From: David Dorward <david@dorward.me.uk>
Date: Thu, 14 Feb 2008 23:22:31 +0000
Message-Id: <F7152E38-8784-4587-85DF-AF470D28B713@dorward.me.uk>
To: www-validator@w3.org
On 14 Feb 2008, at 20:09, Frank Ellermann wrote:
> Yes, that is correct, you cannot have other elements in a
> script.  A HTML trick to get around this could be to put
> the content of the script into a comment:
> | <script type="text/javascript"><!--


That lets user agents which don't understand <script> elements (like  
Netscape 1.0) avoid rendering the content of the script element as  
content. It is pointless on the web of 2008.

The script element is defined as containing CDATA in the HTML DTDs,  
so the comments are treated like the rest of the code within the  
element - as CDATA, not HTML comments.

> | (...) <style type='text/css'> (...) </style> (...)
> | //--></script>
> For XHTML it's more convoluted, something like:
> | <script type="text/javascript"><!--//--><![CDATA[//><!--
> | (...) <style type='text/css'> (...) </style> (...)
> | //--><!]]></script>

And don't do that.

Having nothing more then the CDATA markers is enough, as is using  
&gt; and friends instead of < and co...

... unless you are serving as text/html (making using XHTML in the  
first place, almost certainly, pointless) in which case the  
specification tells you to use an external script.

David Dorward

Received on Thursday, 14 February 2008 23:23:04 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:59:06 UTC