11.01
When using XHTML, the contents of <script> and <style> elements must be marked as CDATA. This is essential when serving XHTML correctly (as application/xhtml+xml).
When possible, use external script and style files and reference these from your XHTML document (behavioural and presentational separation). However, the examples below show how to place <script> and <style> inside your XHTML document correctly. This method should be compatible with older browsers, and therefore degrades gracefully.
Marking <script> as CDATA:
<script type="text/javascript">
<!--//--><![CDATA[//><!--
......
//--><!]]>
</script>
Marking <style> as CDATA:
<style type="text/css">
<!--/*--><![CDATA[/*><!-- */
......
/*]]>*/-->
</style>
ASP.NET 2.0
If you are serving ASP.NET pages as application/xhtml+xml (see Serving the Correct MIME Type for XHTML using ASP.NET 2.0), then the automatically generated JavaScript will not be marked as CDATA, and will therefore not work. For a workaround see: Marking ASP.NET 2.0 Generated JavaScript as CDATA.
Hello, thank you, this is a good reference.
Just the style example ends with a closing script tag and it seems it should be a closing style tag.
Hi Luis, thanks for letting me know. I’ve corrected that mistake.