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?
It cannot be done.
-->
will always end an existing HTML comment.try using this
this is the start of the comment
-->
end of the comments.If you're really stuck with some piece of HTML – pre-rendered at some uncontrollable source – which contains comments, and you need to make sure none of it is rendered on your page, you can always wrap it with a
script
tag like below, only thing is, you can't comment outscript
tags this way.If you need to comment out
script
tags, you could use atextarea
as wrapper instead, off course doing it this way, you can't comment outtextarea
tags.I think it isn't allowed, but as far as I know it works in most of the major browsers except in Firefox.
Try this
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.