views:

1334

answers:

5

Hello, as per the title; is it possible to have nested comments in valid HTML? see the example below...

<p>some text</p>

  <!-- comment 1

    <p>commented out html</p>

    <!-- comment 2

      // are nested html comment allowed?

    end of comment 2 -->

    <p>more commented out html</p>

  end of comment 1 -->

<p>some more text</p>

It appears not, does anybody know how I could get nested comments to work?

Thanks in advance.

+4  A: 

It cannot be done... --> will allways end an existing html comment

Sergio
+7  A: 

When you nest a comment, replace "--" with "- -". When you un-nest, reverse the procedure. It's not the <!-- that is forbidden but the --.

Aaron Digulla
Does this mean the inner comment is no longer a proper comment?
S.Lott
Yes, HTML and XML don't allow to nest comments using <!--. What you can do in your own code is define a comment *element* and ignore it actively during parsing.
Aaron Digulla
+1  A: 

Some editors have commenting/uncommenting commands which can automatically handle existing comments in a block of text. Visual Studio e.g. is doing that when you press Ctrl+KC and Ctrl+KU.

0xA3
A: 

I think it isn't allowed, but as far as I know it works in most of the major browsers except in Firefox.

Hippo
for the time being :-)
LeonixSolutions
A: 

try using this

<!--

this is the start of the comment

<%-- this is another comment --%>

<%-- this is another one --%>

--> end of the comments

drw