1. Computing & Technology

Discuss in my forum

Comments in Internet Explorer

Tricks with Comments that Only Work in Microsoft Internet Explorer

By , About.com Guide

The <comment> Element

The <comment> element is an HTML tag that is available only for Internet Explorer (versions 3 and up). This tag allows you to hide things from Internet Explorer.

In browsers other than Internet Explorer, the comment tag is ignored, and all items within it are parsed and displayed as usual.

You use the comment tag like you would any other tag:

<comment>This text is hidden from IE</comment>

It requires the closing tag.

Using Internet Explorer 6 and JavaScript you can read the number of characters in the <comment> with the comment.length property.

The <comment> element is not valid XHTML or HTML.

If you use the <comment> element, you are automatically creating invalid HTML. But as long as that doesn't bother you, it's a great way to hide aspects of your page from Internet Explorer users, while displaying them to users of other browsers.

The <comment></comment> Element
The <!-- comment --> Element

Previous: Conditional Comments

©2012 About.com. All rights reserved.

A part of The New York Times Company.