HTML conditional statement if IE

Sharikov Vladislav picture Sharikov Vladislav · Apr 16, 2014 · Viewed 9.7k times · Source

I never thought that I am stupid, but... I found hundreds of ways to create if statement in html. Some says that right way is:

<!--[if IE]>
   You're using IE!
<![endif]-->
<![if !IE]>
   You're using something else!
<![endif]>

Or this:

<![if !IE]>
//code
<![endif]>

Or look this fiddle: http://jsfiddle.net/APFZh/2/

All of this DON'T works on my pc. Why? All says that "you have to do this..." and such answers are suggested, so they have to contain working examples, but...

Why they don't work in my browsers? What is the correct way to write conditional statements? Is example from fiddle is working?

enter image description here

I tried to open fiddle in ie 11, not with FF and changed useragent. Epic.

Why it is so ? What I have to do? Help me please!

Answer

Dryden Long picture Dryden Long · Apr 16, 2014

Conditional comments were disabled in IE10 so they will not work in IE11.

Source

In order to have conditional statements you can use Javascript to detect the browser. Since I see Mootools in your screenshot, here is a guide on how to do that.

Or, here is a JS library that is pretty good: WhichBrowser

That being said, browser sniffing is not recommended. Look into Feature Detection instead.