Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 347
vikmalhotra Avatar asked Sep 21 '10 03:09

vikmalhotra


People also ask

How do you uncomment multiple lines in HTML?

You can comment multiple lines by the special beginning tag <! -- and ending tag --> placed before the first line and end of the last line as shown in the given example below.

How do you comment out HTML code?

To “comment out” a button — or any HTML element— simply wrap the element in the< !

What does uncomment mean in HTML?

Uncomment HTML. Commenting is a way that you can leave comments for other developers within your code without affecting the resulting output that is displayed to the end user. Commenting is also a convenient way to make code inactive without having to delete it entirely. Comments in HTML start with <!--


2 Answers

Yes, to comment structural metadata out,

Using <script>/* ... */</script> in .html

Comment out large sections of HTML (Comment Out Block)

my personal way in a .html file is opening: <script>/* and close it with */</script>

<script>/* hiding code go here */</script>

Is a workaround to the problem since is not HTML.

Considering your code in .html...

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

And in a case is HTML inside PHP file using comment tag <?/* or <?php /* and close it with */?> . Remember that the file must be .php extension and don't work in .html.

<?/* hiding code go here */?>

Considering your code in .php...

  <!-- 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> */?> 

Is worth nothing that is not HTML but a common developer practice is to comment out parts of metadata so that it will not be rendered and/or executed in the browser. In HTML, commenting out multiple lines can be time-consuming. It is useful to exclude pieces of template structural metadata containing comments, CSS or code and systematically commenting out to find the source of an error. It is considered a bad practice to comment blocks out and it is recommended to use a version control system. The attribute "type" is required in HTML4 and optional in HTML5.

like image 132
Alan Mattano Avatar answered Sep 29 '22 00:09

Alan Mattano


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/

like image 21
Robert Avatar answered Sep 29 '22 01:09

Robert