I decided to show a breaking version of what I am talking about. It is not important how it messes up the layout, only that it causes the DIV element to be null….
<!-- [ top panel ] --><div id="top_panel">
<!-- -------------------------------------- -->
<script type="text/javascript">
alert(document.getElementById('top_panel'));
</script>
</div>
The above code will return the element as null, every time…. if I increase or decrease the number of dashes it still fails as long as the interior dashes end with a closing pair of dashes. For the sake of example, I will use [open] and [close] to represent pairs of “–” dashes…
So, the code ends up being interpreted this way to break:
<!-- [close][open][close][open][close][open][close][open][close] -->
In this example, it is the last [close] and the “–>” which now cause an open, hanging comment.
I only seem to run into comment-based issues in FF these days. All other browsers seem okay with anything I have thrown at them…
I KNOW that this is not considered legal commenting, but it still does not change the fact that I had to trip over this situation to become aware of the issue… I am hoping others can avoid the same simple problem and share their own twists on weird, comment-based issues in any browser… I am sure this is not the only instance of good commenting gone bad.
I also understand that leaving a space after the “<” is a no-no as well: “<” + ” ” + “!” + “–” = Nooooo!
Thanks for all your help, all!
You can’t use
--inside comments because it ends the comment. This isn’t a Firefox thing – it’s defined by the standards. Any browser that doesn’t treat--as start/end of comment is doing it wrong and most likely will be bug-fixed eventually.