views:

79

answers:

2

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!

+5  A: 

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.

White space is not permitted between the markup declaration open delimiter("<!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter (">"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.

Mark Byers
Thanks, I already knew about the double dashes (read my question), but you did give me what I was looking for, which was a link to the actual documentation on the whole comment issue. So, no points for restating what i already knew, but big points for finding the link. For some reason, I could not seem to get a hold of this via google.
exoboy
I also found that as long as you have a tag that self-closes, you CAN get away with LOOKING like you are using dashes in your comment.... <!-- -- -- -- -- -- -- --> works because the last --> acts as the close for the next-to-last -- .
exoboy
It basically just then becomes a group of comments: [comment][comment][comment][comment][comment]
exoboy
+1  A: 

Are you serving XHTML? According to the XML standard,

For compatibility, the string " -- " (double-hyphen) MUST NOT occur within comments.

Edit: the same restriction exists in regular HTML, too.

Dean Harding
Please be sure when responding to questions that yo do not just restate what has already been said in the original question, I was not asking if the dashes are okay.... I was looking for any ADDITIONAL situations when a comment might cause problems.
exoboy
Again, it is not the "--" that is the problem, the real problem is whether or not it is paired in an opening and closing "--". As long as you remember this fact, you can make it appear like you are using dashes in your comment: <-- -- -- -- -- --> works because the "--" are all paired properly.
exoboy