How to make HTML code inactive with comments
I have some HTML code on a开发者_运维百科 page that I don't want to erase, but make inactive for the short term. How can I make the browser ignore parts of the page in the same way the //
works in some programming languages?
Behold HTML comments:
<!-- comment -->
http://www.w3.org/TR/html401/intro/sgmltut.html#idx-HTML
The proper way to delete code without deleting it, of course, is to use version control, which enables you to resurrect old code from the past. Don't get into the habit of accumulating commented-out code in your pages, it's no fun. :)
HTML Comments:
<!-- <div> This div will not show </div> -->
See Reference
CSS Comments:
/* This style will not apply */
See Reference
JavaScript Comments:
// This single line JavaScript code will not execute
OR
/*
The whole block of JavaScript code will not execute
*/
See Reference
To comment block with nested comments: substitute inner (block) comments from "--" to "++"
<!-- *********************************************************************
* IMPORTANT: To uncomment section
* sub inner comments "++" -> "--" & remove this comment
*********************************************************************
<head>
<title>My document's title</title> <++! My document's title ++>
<link rel=stylesheet href="mydoc.css" type="text/css">
</head>
<body>
<++! My document's important HTML stuff ++>
...
...
...
</body>
*********************************************************************
* IMPORTANT: To uncomment section
* sub inner comments "++" -> "--" & remove this comment
*********************************************************************
-->
Thus, the outer most comment ignores all "invalid" inner (block) comments.
Just create a multi-line comment around it. When you want it back, just erase the comment tags.
For example, <!-- Stuff to comment out or make inactive -->
Use:
<!-- This is a comment for an HTML page and it will not display in the browser -->
For more information, I think 3 On SGML and HTML may help you.
If you are using Eclipse then the keyboard shortcut is Ctrl + Shift + / to add a group of code. To make a comment line or select the code, right click -> Source -> Add Block Comment.
To remove the block comment, Ctrl + Shift + \ or right click -> Source -> Remove Block comment.
Reason of comments:
- Comment out elements temporarily rather than removing them, especially if they've been left unfinished.
- Write notes or reminders to yourself inside your actual HTML documents.
- Create notes for other scripting languages like JavaScript which requires them
HTML Comments
<!-- Everything is invisible -->
精彩评论