Link to home
Start Free TrialLog in
Avatar of ollyatstithians
ollyatstithiansFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using <comment> tag to reverse IE conditional comments

I want an image to be used in IE, but a different one to be used in other browsers. I can get the IE image to display only in IE by using conditional comments. I can also get the non IE image not to display in IE by using the non-standard <comment> tag.
The problem with this is that it makes my HTML invalid. My solution was to enclose the <comment> tag and its corresponding </comment> in conditional comments, so that Firefox et al ignored it, making the page valid once again.
The idea seems sound to me, but sadly the closing </comment> does not work in a conditional comment. Probably because IE is waiting for the closing comment before it evaluates the condition. My code is below. Any solutions to this?

Thanks,

Olly.
<!--[if IE]>
  <img src="img/IEImage.jpg" alt="This image should be displayed only in IE">
  <comment>
<![endif]-->
  <img src="img/OtherImage.png" alt="This image should never be displayed in IE">
<!--[if IE]>
  </comment>
<![endif]-->

Open in new window

Avatar of ollyatstithians
ollyatstithians
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

BTW I am looking for a way to choose one image over another in an <img> tag. I am aware I can use CSS as a workaround.
ASKER CERTIFIED SOLUTION
Avatar of ollyatstithians
ollyatstithians
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial