HTML comments are a way to remind you and anyone who works on your HTML documents of
what exactly you were thinking when you created a particular Web page. You can use comments to
explain specific portions of a document. You can also use comments to insert personal information
like your name, address, and phone number in the Web page HTML, so anyone interested in obtaining
your services as a Web designer will know how to contact you.
In addition, you might use comments to temporarily hide some of the Web document’s HTML
statements from the Web browser. Suppose, for example, you want to add a section of HTML code
to an existing document, but you do not want the browser to display the new content until management
gives permission to proceed. Placing HTML comment tags (<!– – – –>) around the statements you
want to hide instructs the Web browser to ignore the statements until you remove you comment tags.
To create a comment, enclose the informational text (or the HTML statements you want
to comment out) within the start and end comment tags, such as <! – – comment – –>.
Placing a begin comment tag before each line of text or HTML statement is not necessary; the Web
browser will ignore anything it finds after the start comment tag and before the next end comment
tag. For example, the following code shows three lines of comments inserted within the Web page
header section:
<head>
<title> A document containing comments </title>
<! -- Author Andy Anderson
Company One-of-a-Kind Productions, Inc.
Contact Info 316 333 4444 -- >
</head>
Although the Web browser does not display the information you place between start and end
comment tags onscreen, a site visitor can still read the comments by instructing the Web browser to
display the Web page HTML. The browser, in turn, will display the source code (including comments)
for the HTML document in a separate document window.
Besides using comments to identify personal information, you can use comments in a training
environment to help explain the purpose of specific HTML tags and attributes to your students. In
addition, you might use comments to prevent the display of embedded scripts onscreen when the
Web browser does not support the script tag, as shown in the following code:
<html>
<head>
<script language="JavaScript">
<!--
function displayIt()
{
alert("This JavaScript function displays this text in the browser window!")
return;
}
//-->
</script>
</head>
<body>
... Web Page Content the Browser is to Display Goes Here ...
</body>
</html>
Without the comment tags around the JavaScript function definition in this example, Web browsers
that do not support the script tag may ignore the tag and display the JavaScript code as text onscreen.
Conversely browsers supporting scripts ignore the HTML comment tags because scripts use // and
/* */ to denote comments.
0 comments:
Post a Comment