Home Articles Uncategorized Targeting IE or everything except IE

Targeting IE or everything except IE

I’ve known for a long time that you can use conditional statements to target Internet Explorer while excluding all the other browsers. Today I learned something new — you can do it in reverse. You can exclude IE from seeing code without effecting the rest of the browsers.

This came into need when I wanted to use a script that wouldn’t render properly because of IE’s bugs. Instead of targeting the other 4 browsers, I found a quick and easy solution at Javascript Kit.

The first is the code we all know. The second is the exclusion code. Notice the exclamation point before the “IE”:

<!--[if IE]>
Only show this code to IE users
<![endif]-->

<![if !IE]>
Show this code to everyone except IE users
<![endif]>

This exclusion code works with the different conditional options as well. Just to review:

<!--[if lt IE 7 ]> Less than IE7. Target only IE6 and below.
<!--[if lte IE 7 ]> Less than or equal to IE7. Target IE7 and below.
<!--[if gt IE 7 ]> Greater than IE7. Target only IE8 and above.
<!--[if gte IE 7 ]> Greater than or equal to IE7. Target IE7 and above.

Target Internet Explorer 11 via CSS

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
     /* IE11 CSS styles go here */
}