Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an "else" in an IE HTML conditional?

<!--[if lt IE 9]>     This is less then IE9 ELSE     this is all browsers: firefox, chrome, etc. <![endif]--> 

How do I do this in my HTML? I want to do an "else" ...

like image 723
TIMEX Avatar asked Jul 19 '11 03:07

TIMEX


People also ask

How do you add an if else condition in HTML?

Conditional Statements Use if to specify a block of code to be executed, if a specified condition is true. Use else to specify a block of code to be executed, if the same condition is false. Use else if to specify a new condition to test, if the first condition is false.

Can you do conditional statements in HTML?

How to Build HTML for Conditional Links. Like we learned in the above example, conditional statements are best used outside your the Insert Link html elements. You will want to define your primary condition, then build the content to display after. Use {% else %} for your fallback content, and end with {% endif %}.

Is there if else in HTML?

The <! --[if IE]> syntax only works in Internet Explorer. You'll need to use javascript or css to conditionally display html in other browsers.

What is if else statement in JavaScript?

The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. The if/else statement is a part of JavaScript's "Conditional" Statements, which are used to perform different actions based on different conditions.


2 Answers

You're not looking for an else, you're looking for <![if !IE]> <something or other> <!--[endif]> (note that this is not a comment).

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

You can find documentation on the conditional comments here.

like image 93
cwallenpoole Avatar answered Oct 13 '22 02:10

cwallenpoole


I use the following to load resources in IE9 or newer and all other browsers

<!--[if gte IE 9]><!-->             //your style or script <!--<![endif]--> 

This is hard to believe. Look the opening and closing if statement sections are inside comments (so, its not visible to other browsers) but visible to IE.

like image 34
Jhankar Mahbub Avatar answered Oct 13 '22 01:10

Jhankar Mahbub