The rules for writing XHTML code are much stricter than writing HTML. Code like the following is valid in HTML, but invalid in XHTML.
[javascript]
In HTML, there are special rules to determine what content in the <script> element can be parsed, but these rules do not apply in XHTML. Because the less than sign (<) will be parsed as starting a new tag in XHTML. However, as a label, the less than sign cannot be followed by a space, thus causing a syntax error. <br>There are two solutions: first, replace all less than signs (<) in the code with the corresponding HTML entities (<); second, use a CData fragment to contain the JavaScript code. <br>Corresponding code for method one: <br>[javascript] <br><div class="codetitle">
<span><a style="CURSOR: pointer" data="41685" class="copybut" id="copybut41685" onclick="doCopy('code41685')"><u>Copy code </u></a></span> The code is as follows: </div>
<div class="codebody" id="code41685"> <br><script type="text/javascript"> <br>function compare(a, b) <br>{ <br>if(a < b) <BR>{ <BR>alert("a is less then b"); <BR>} <BR>else if(a > b) <br>{ <br>alert("a is greater then b"); <br>} <br>else <br> { <br>alert("a is equal to b"); <br>} <br>} <br></script>
This format works well in all modern browsers.
Wrapping JavaScript code in an HTML comment as above allows browsers that do not support the