build-website-header
 
 

Using XHTML/HTML Comments

An XHTML/HTML comment begins with "<!--", ends with "-->".Because of that the comment should not contain "--" or ">" anywhere in the comment.

The following are examples of XHTML comments:

  • <!-- This is a comment. -->
  • <!-- This is another  larger comment,
    and it continues onto a second line. -->

 

Why use XHTML Comments

  • If you are editing a document that may be edited by others then comments are a good way of explaining what you have done and why.
  • Hiding Script from older browsers
  • Documenting script functions and code.
  • Marking out blocks of text or script.
  • Temporarily remove sections from a page.

The one I use the most is "Marking Out Text or Script Blocks".  If you are familiar with Google Adsense then you know that Google provides you with the Adsense code which you simply paste into the document.

The code is usually JavaScript and is not always commented. If you just paste the code into your web page then what happens in a few weeks when you want to locate the code to replace it.

Google also limit the number of Adsense units on the page, currently to 4. How do you check that you haven't exceeded that amount?

Well what I do is to enclose the Google script in comments. So my script instead of looking like this:

<script type="text/javascript"><!--
google_ad_client = "pub-2450899182473293";
google_ad_width = 110;
google_ad_height = 32;
google_ad_format = "110x32_as_rimg";
google_cpa_choice = "CAAQ463zzwEaCH20f7pPcGBpKLPGvnU";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Instead looks like:

<!-- Start Google adsense-->

<script type="text/javascript"><!--
google_ad_client = "pub-2450899182473293";
google_ad_width = 110;
google_ad_height = 32;
google_ad_format = "110x32_as_rimg";
google_cpa_choice = "CAAQ463zzwEaCH20f7pPcGBpKLPGvnU";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<!-- End Google adsense-->

Inserting HTML/XHTMLComments

Because XHTML comments are hidden in most WYSIWYG web page editors you simply can't just type them on the page. Most editors have an XHTML or source option were you can edit the XHTML directly.

However most editors also have the ability to insert a comment without going into the XHTML.

For FrontPage, Trellian WebPage and NVU users choose Insert>comment and a comment box appears just type in the comment without the XHTML/HTML tags (they are inserted by the editor).

Other editors will no doubt be similar

You should note that you will not be able to see the comments you just inserted unless you switch to XHTML/source mode.

 

 Related Articles and Resources:

 
 


Add to My Yahoo!



Free Newsletter!


 

Main menu

Home
Website Design
Website Hosting
Website Promotion

Subscribe To the Blog!


Newsletter