Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Using <comment> tag to reverse IE conditional comments

Posted on 2010-11-09
2
309 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:ollyatstithians
  • 2
2 Comments
 
LVL 10

Author Comment

by:ollyatstithians
ID: 34094722
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.
0
 
LVL 10

Accepted Solution

by:
ollyatstithians earned 0 total points
ID: 34095190
So with a lot of fiddling I have found a way to do conditional comments to be ignored by IE but not other browsers that actually validates.
Essentially you need to close the comment and re-open it either side of the IE ignored code.
<!--[if !IE]>-->
  <p>This will be rendered by non-IE5+ browsers. The conditional comments will appear as 
    HTML comments to the validator and other browsers</p>
<!--<![endif]-->

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS: Making responsive table look nicer 7 31
If condition on Html with Asp 11 28
How to combine and minify CSS and JS files 5 17
parse url to form? 7 25
This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question