Michael J.A. Clark
Michael Clark is a professional software developer who creates high-quality products for startups in Cambridge, UK. Skills: C#, Java, PHP, XHTML, AS3, CSS, ML.

Sections

Contact details

Email
mjac@mjac.co.uk
Skype
mjacdotuk
Twitter
mjacuk

Escaping the content of inline script/style elements

In XHTML, unlike HTML, the script and style elements are declared as having parsed character data (#PCDATA) content — certain characters (such as <>&"') must be represented by character entity references. Wrapping the content of the script or style element within a CDATA marked section avoids having to use these references.

<script type="text/javascript">
<![CDATA[
JavaScript here
]]>
</script>

For these sections to be compatible with both the text/html (HTML) and application/xhtml+xml (XHTML) mime types the following escape strings must be used:

<script type="text/javascript">
<!--//--><![CDATA[//><!--
JavaScript code
//--><!]]>
</script>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
CSS styles
/*]]>*/-->
</style>

Comments