Reputation: 587
IE handles one of my div's classes totally wrong. It works in every other browser I tried. I want to simply not apply the class to the div in IE. Is there a trick to make IE not apply it?
More info: The div has multiple classes. I want to still load one but not the other in IE. The classes are defined in a Javascript file.
Thanks. Mike
Upvotes: 2
Views: 1490
Reputation: 91762
You can reset that specific style in a IE only stylesheet using something like this in the head section:
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" media="screen" href="/styles/ie.css" />
<![endif]-->
(for IE 7 and below...)
Update to reflect some of the comments: You can target all non-IE browsers as a whole using this in your document (in the head if you go for styles):
<!--[if !IE]><!-->
/* some styles AND / OR javascript */
<!--<![endif]-->
Upvotes: 5
Reputation: 49425
I hate to do browser detection via javascript, but if none of the other solutions work you might try something like the following:
function removeClassForIE() {
// Look at userAgent to test for IE
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
if (divs[i].className == "myClassName") {
divs[i].className = "";
}
}
}
}
That should remove the class from those divs, and only if its IE. You could call the function like <body onload="removeClassForIE();">
Upvotes: 0
Reputation: 525
You can use conditional comments for IE to override the style on the class - that might be the easiest thing. Have a look here: MSDN link Essentially, you'd assign a more specific style to the class in the comment, overriding the standard - so, you could take most of the styling off. Intelligent browsers won't see the comment.
Upvotes: 6