The following code is for reliable cross-browser IE version detection
<!--[if lt IE 7 ]><body class="ie_6"><![endif]-->
<!--[if IE 7 ]><body class="ie_7"><![endif]-->
<!--[if IE 8 ]><body class="ie_8"><![endif]-->
<!--[if IE 9 ]><body class="ie_9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body>
<!--<![endif]-->
What I don’t understand is, why it’s working.Why the normal <body> didn’t overwrite the <body class="ie_9"> since it is just a normal tag, should be recognized by all the browsers.
What’s the magic about
<!-->
<body>
<!--
You probably want to change
!(IE)to(!IE)Also, the “normal”
<body>tag you’re talking about is in a conditional comment. The fact that it’s on a different line doesn’t matter, it’s still inside the conditional comment tag, so is affected as such.Conditional comments for IE work by using normal HTML comments
<!-- -->so any code inside a “false” conditional is just commented out;<!-- <body class="ie6"> -->IE then has its own syntax inside of that. As such, non-IE browsers just see a commented string, and IE treats it as a statement to execute.Because of this, only one body tag shows, and only that one gets used.
More explanation of
To IE, this says:
If you don’t understand why, read the paragraph starting “Conditional comments for IE work…”.
This same block, to any other browser looks like this: