Joel Martinez
Joel Martinez

Reputation: 47751

Check for IE6 in a jQuery selector

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

Upvotes: 0

Views: 4135

Answers (2)

montrealist
montrealist

Reputation: 5693

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;
}

Upvotes: 2

Noah Medling
Noah Medling

Reputation: 4669

You can use the (deprecated) browser attribute:

if ($.browser.msie && $.browser.version.substring(0,1) === '6') {
    ...
}

Upvotes: 2

Related Questions