Can <!--[if lte IE 8]> even work in IE6? - html

I am just about at making my website compatibility, and with IE, the old jerk, I need to use
<!--[if lte IE 8]>
<![endif]-->
However, as "lte IE8" means "equal to or less than IE8", how can IE6 even read this ?
Also, is it lt or lte ?
http://www.quirksmode.org/css/condcom.html refers both, though only lte in it's definition.

Conditional comments are forwards-compatible. IE detects the number after the "IE" token and compares it to its current version. It doesn't have a built-in whitelist "IE7, IE8" or anything. It will work.

To answer one part of your question, which no-one seemed to answer explicitly and I have been trying to figure out ...
is it lt or lte?
Without realising what lt and lte are, you might be unsure which to use, however from reading other comments, I realised that lt = less than and lte = less than or equal to (similary gt and gte are greater than and greater than or equal to), so it depends which versions of IE you want the rule to apply to as to whether you use lt, lte or a combination.

I suppose you can look at it as an expression:
<!--[if expression]> HTML <![endif]-->
Another example would also work:
<!--[if true]> HTML <![endif]-->
About conditions

Related

Conditional comments syntax

Can anyone explain me the difference between first and second conditional comment syntax?
<!--[if lt IE 8]><html class="no-js lt-ie8"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
Why the second one use use the <!--> syntax before <html> tag? Can I use the following syntax with the same result?
<!--[if lt IE 8]><html class="no-js lt-ie8"><![endif]-->
<!--[if gt IE 8]><html class="no-js"><![endif]-->
Thanks in advance!
No, your second setup will not be the same as your first.
In the first, where <!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]--> is used, it will let all other browsers (the one's that does not understand conditional comments) to have <html class="no-js">, which the second setup won't
Src: https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
General accepted syntax is (was)
open tag : <!--[if condition version]>
end tag : <![endif]-->
Best guess is that its an attempt at a bogus comment. Two dashes after <! make it a comment node in the DOM. Refer this answer
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
^^^^^ ^^^^
||||| ||||
________Bogus Comment________
It doesn't really make any difference. The last one will probably render as a <!-- comment --> or a comment + condition ... not sure.

difference between conditional comments <!--[if lt IE 9]> and <!--[if lte IE 8]>

Is there any difference between conditional comments <!--[if lt IE 9]> and <!--[if lte IE 8]>
The first one of course means less than IE9.
The second one means less than or equal IE8.
Are they equivalent or not?
As if Internet Explorer 8.X does not exist, YES they are equivalent !
if there is a version IE 8.x it will be deny by lte IE8 but accept by lt IE9
but as Ksv3n say, there is no IE8.x, so on this case they are equivalent

How do I replace an id tag inside a div if seen in IE

I have this html line
I am trying to make it so that when IE reads that line, it changes the "listHr" id to "listhrIE".
I have tried this, in an attempt to switch out the line altogeather, but no luck:
<hr id="listHr"></hr> <!--[if IE]><id="listHrIE"></hr><![endif]-->
I am sure I am doing this wrong. What is the correct way of doing this?
Thanks.
IE tags have a "not IE" component.
<!--[if IE]>
<hr id="listHrIE"></hr>
<![endif]-->
<![if !IE]>
<hr id="listHr"></hr>
<![endif]>
However I'd offer a better way to do it would be to just override the style of listHr when IE is detected
As #Paulie_D pointed out: conditional tags are deprecated and won't work for IE 10 and above. You can use a special meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
to force them to work however this is not recommended. See here: http://msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx
try these:
<!--[if !IE]><hr id="listHr"></hr><!-->
<!--[if IE]><hr id="listHrIE"></hr><!-->
if you want set this id for some version of IE, you can do this:
greater and equal IE8:
<!--[if gte IE 8]><!-->
less and equal IE8:
<!--[if lte IE 8]><!-->
equal IE8:
<!--[if IE 8]><!-->
You can use IE only conditional tags to detect IE.
Just like:
<!--[if IE ]>
<p>Welcome to Internet Explorer 8.</p>
<![endif]-->
So, In your case you need two things to change ID.
1) Display IE only ID
2) Hide non-IE ID
To apply IE only ID you need following conditional tag code
<!--[if IE ]>
<div id="listHrIE"></hr>
<![endif]-->
To hide non-IE ID you need to add display:none
<!--[if IE ]>
<div id="listHrIE"></div>
<div id="listHr" style="display:none"></div>
<![endif]-->
Now you can style your IE Only ID in way you want and it will only replace listHr when IE detects.
Update: To target IE 10 Use following jQuery: Before using add jQuery Migrate
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script> This line
to your page<head>
Then add
if ($.browser.msie && $.browser.version == 10) {
$("html").addClass("ie10");
}
I hope this helps :)

Can I use "if lt IE9" in conjunction with "if IE 8"?

Can I use if lt IE9 in conjunction with if IE 8, in this manner:
<!--[if lt IE 9]><script src="html5shiv.js"></script><![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
I'm asking since the second condition is contained in the first one, maybe this could cause some glitch in one of the browsers?
Yes it should work fine, and the order doesn't matter, ie will parse all the rules and execute any that matches

How can I detect if a browser is IE 8 or IE 9 without Javascript?

I have seen the following:
quirksmode
But this does not really show how I can detect for IE8 or IE9. Can someone tell me how I can do this with conditional comments?
The link you posted is correct. Those comments are what you need.
<!--[if IE 8]>
According to the conditional comment this is IE 8<br />
<![endif]-->
<!--[if IE 9]>
According to the conditional comment this is IE 9<br />
<![endif]-->
<!--[if (IE 8)|(IE 9)]>
According to the conditional comment this is IE 8 or 9<br />
<![endif]-->
Conditional Comments (for your reference):
http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
Between the square brackets are your conditions, you can do equals, not equals, less than, less than or equal to, greater than, greater than or equal to.
You can use conditional comments in Internet Explorer to add a CSS class to your HTML node. This is how html5boilerplate works to add browser specific CSS:
https://github.com/h5bp/html5-boilerplate/blob/master/index.html
For each browser you can use different kind of "conditional comments"
here is one of very good article by Chris Coyier over this issue.
http://css-tricks.com/new-poll-conditional-tags-for-all-browsers/
it is my personal experience it was good to use conditional comments.
yes you can detect ie8 and 9 also. Try this
<!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->
<![if !IE]><p>You are not using Internet Explorer.</p><![endif]>
<!--[if IE 8]><p>Welcome to Internet Explorer 8!</p><![endif]-->
<!--[if !(IE 9)]><p>You are not using version 9.</p><![endif]-->
<!--[if gte IE 8]><p>You are using IE 8 or greater.</p><![endif]-->
<!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
<!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
<!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->
<!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
<![if false]>You are using a <em>downlevel</em> browser.<![endif]>
<!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]-->
In the if condition expresions lte denotes less than or equal to and gte denoted greater than or equal to and lt denotes less than.