Michael J.A. Clark
Michael Clark is a Computer Science student from England providing freelance programming and design when not studying at Cambridge. Skills: C#, Sitecore, PHP, XHTML, CSS, AS3, Java, ML, F#.

Sections

Contact details

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

Inline style and script 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. Simply trying to understand these escape strings is useful as it reinforces core knowledge of HTML and XHTML syntax.

JavaScript template

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

CSS template

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

Comments