Conditional Comment - Syntax

Syntax

There are two types of "conditional comments": downlevel revealed, and downlevel hidden.

The basic syntax of each type of comment is shown in the following table. The first comment shown is the basic HTML Comment, which is included for the purpose of comparison and to illustrate the different syntax used by each type of conditional comment.

Comment type Syntax or possible value
standard HTML comment
downlevel-hidden HTML
downlevel-revealed HTML

The HTML shown inside the syntax block in each of the conditional comments denotes any block of HTML content, including script. Both types of conditional comment use a conditional expression to indicate whether the content inside the comment block should be parsed or ignored. The conditional expression is formed from a combination of feature, operator, and/or value, depending on the feature. The following table shows the supported features and describes the values each feature supports.

Item Example Comment
IE The string "IE" is a feature corresponding to the version of Internet Explorer used to view the Web page.
value An integer or floating point numeral corresponding to the version of the browser. Returns a Boolean value of true if the version number matches the browser version. For more information, see Version vectors.
WindowsEdition Internet Explorer 8 on Windows 7. The string "WindowsEdition" is a feature corresponding to the edition of Microsoft Windows used to view the Web page.
value An integer corresponding to the edition of Windows used to view the Web page. Returns a Boolean value of true if the value matches the edition being used. For information about supported values and the editions they describe, see the pdwReturnedProductType parameter of the GetProductInfo function.
true Always evaluates to true.
false Always evaluates to false.

The following table describes the operators that can be used to create conditional expressions.

Item Example Comment
The NOT operator. This is placed immediately in front of the feature, operator, or subexpression to reverse the Boolean meaning of the expression.
lt The less-than operator. Returns true if the first argument is less than the second argument.
lte The less-than or equal operator. Returns true if the first argument is less than or equal to the second argument.
gt The greater-than operator. Returns true if the first argument is greater than the second argument.
gte The greater-than or equal operator. Returns true if the first argument is greater than or equal to the second argument.
( ) Subexpression operators. Used in conjunction with boolean operators to create more complex expressions.
& The AND operator. Returns true if all subexpressions evaluate to true
| The OR operator. Returns true if any of the subexpressions evaluates to true.

Read more about this topic:  Conditional Comment