views:

1820

answers:

2

Is there any way to do something conditionally in jquery only if IE6 is the browser? An example of the kind of thing I'm looking for is as follows:

$("#someselector").IsIE6().css("position", "relative").css("left", 40);

I'm plagued by a strange problem with the JQuery UI dialog and adding this code resolves the issue, but obviously messes up all the other browsers

+2  A: 

You can use the (deprecated) browser attribute:

if ($.browser.msie && $.browser.version.substring(0,1) === '6') {
    ...
}
Noah Medling
+2  A: 

jQuery is probably overkill for this.

Why not just have a conditional statement inside the HEAD of your document which optionally loads a stylesheet with 'IE-6-only' rules? This way everything will still display correctly even if the user has JS disabled.

<!--[if lt IE 7]>
        <link type="text/css" rel="stylesheet" media="all" href="ie6.css" />
<![endif]-->

Then in your ie6.css you can have a rule like this:

#someselector {
    position: relative;
    left: 40px;
}
dalbaeb
because the styles must be set programmatically. I'm trying to work around a faulty jquery plugin that sets styles which cause layout issues in IE6. I'd rather avoid cracking open the 3rd party code and trying to figure out how it works in order to fix the problem. I've identified the styles which fix it for IE6
Joel Martinez