Search code examples
htmlcoding-stylecomments

How to comment/uncomment in HTML code


Often while coding view templates in html, my habit of adding some helpful comments causes lots of time-consuming effort while testing.

Consider this code...

<!-- Here starts the sidebar -->
<div id="sidebar">
....
</div>

<!-- Here starts the main contents pane -->
<div id="main-contents">
...
</div>

<!-- Here starts the footer -->
<div id="footer">
...
</div>

Now, if I have to hide out some portion of the view template, in case of php I would just select the desired code and put single-line comments (using a shortcut key most of the times).

However, in html code, where only the block comments work, I end-up removing all the closing comment tags (-->) till the position I want the commenting to occur - something like this...

<!-- Here starts the sidebar
<div id="sidebar">
....
</div>

<!-- Here starts the main contents pane
<div id="main-contents">
...
</div>

<!-- Here starts the footer
<div id="footer">
...
</div>-->

Then when I'm done testing I have to go through the agony of putting back those closing tags.

Is there a better and time saving way of block commenting in HTML?


Solution

  • Depends on the extension. If it's .html, you can use <? to start and ?> to end a comment. That's really the only alternative that I can think of. http://jsfiddle.net/SuEAW/