In XHTML, the script and style elements are declared as having
#PCDATA
content. As a result, <
and
&
will be treated as the start of markup, and
entities such as <
and &
will be recognized as entity references by the XML processor to
<
and &
respectively. Wrapping
the content of the script or style element within a
CDATA
marked section avoids the expansion of these
entities.
<script type="text/javascript"><![CDATA[ if (i < 5) && (j < 10) alert("What sweet sorrow!"); ]]></script>
An alternative is to use external script and style documents!