Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML IF Statement

I just wanna know how to do an if-statement in simple HTML. Like the [if IE6] thingy

I'd like to do something like this

[IF 5>6]

How's the syntax? I can't seem to find anything but [If!IE6] and things like that, is that even possible?

Thanks a lot

Edit: I want to compare just scalar numbers, cause I have a dynamically created HTML. For example [If 4 == 6]. I DON'T WANT TO CHECK IE VERSIONS.

like image 800
Maggie Fortelli Avatar asked Feb 24 '12 15:02

Maggie Fortelli


People also ask

How do you add an if statement in HTML?

Conditional StatementsUse 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.

Does HTML have if statements?

Not in HTML. Consider using JavaScript instead.

Can you use conditional statements 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 %}.


1 Answers

If you want to check for browser versions:

<!--[if lt IE 7]>
    <!-- For LOWER than IE7 -->
<![endif]-->

<!--[if IE 6]>
    <!-- For JUST IE6 -->
<![endif]-->

<!--[if gt IE 7]>
    <!-- For HIGHER than IE7 -->
<![endif]-->

Other than that, you cannot use if statements in HTML, as it is a markup language and not a programming language. You need to do it either server side or with Javascript.

like image 140
Nix Avatar answered Sep 27 '22 00:09

Nix