I have a function like this one (below) which inserts a block of HTML code in an HTML page:
function someEventHandler(htmlContent)
{
document.getElementById('some-element-id').innerHTML = htmlContent;
}
This works fine for HTML code that includes an img
tag.
When the HTML code includes <script>
blocks, though, they do not render. Furthermore, the script blocks contain JavaScript that is surrounded by HTML comments. For example:
<script type="text/javascript">
<!--
function someFunctionThatRendersStaticImageOrFlash()...
-->
</script>
These script blocks that contain HTML comments do not render after they have been inserted. I have control over the code that is inserted and I tested it without the HTML comments, and they rendered successfully.
It is my understanding that HTML comments like this were used in early versions of Netscape, to prevent problems with browser incompatibility with javascript.
Is there any other reason (or any good reason) to include HTML style comments in a javascript block?
Edit
I mistyped. The closing comment is: //-->
.