Forum Moderators: open
<script type="text/javascript">
<!--
//-->
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>HTML Comments In SCRIPT are *NOT* needed</title>
</head>
<body>
<script type="text/javascript">
alert('this is in a script element with no html comments');
// It validates just fine, thank you very much!
</script>
</body>
</html>
<script type="text/javascript">
//<![CDATA[
document.write('<script>alert("this is in a script element with no html comments")<\/script>');
// It validates just fine, thank you very much!
//]]>
</script>
If, however, you DO decide to include your JavaScript code within your HTML page, then the correct way to do so is not with HTML comments, but by placing the code within a CDATA section.
"In XHTML [w3.org] ... < 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[
...
]]>
</script>
<script type="text/javascript">
//<![CDATA[
...
//]]>
</script>
<script type="text/javascript">
/* <![CDATA[ */
...
/* ]]> */
</script>
<script type="text/javascript">
...
</script>
<script>
...
</script>