Is there any option for using IF-ELSE conditioning in HTML tags
<if true> do something </if>
<else> do something </else>
Is there any option for using IF-ELSE conditioning in HTML tags
<if true> do something </if>
<else> do something </else>
Not to be pedantic, but HTML is a markup language, and isn't useful for conditional logic.
That being said, it sounds like what you're looking for is a bit of javascript. If you could add a bit more detail to your question, I could elaborate on how you could use javascript to do tasks with conditional logic.
There is, but it's really only used in IE to distinguish between different versions:
<!--[if IE6]>
Things here!
<![endif]-->
HTML was designed for document layout so the noscript and noframes are about as close as HTML gets to handling conditionals. You could conceivably approach this problem with javascript.
<div id='if-part' style='visibility: hidden;'>do something</div>
<div id='else-part' style='visibility: hidden'>do something</div>
<script>
var node;
if(true) {
node = document.getElementById('if-part');
}
else {
node = document.getElementById('else-part');
}
node.style.visibility = 'visible';
</script>
of course this only works if the client has javascript turned on.
Conditional rendering of HTML is not a new concept, but it cannot be done using HTML exclusively. You would need to use either client side scripting or server side code to provide the conditional logic that would render your HTML accordingly.
JavaScript ... conditional comments have no place in HTML. Even the old IE6 & IE7 comments were not quite valid either.
As has been said in other posts, HTML does not support conditional logic. You have two choices here:
1) Generate the HTML dynamically using technologies such as PHP or XSLT
2) Modify the HTML DOM after the fact using Javascript