views:

23127

answers:

6

Anyone have any ideas on how to test for something specific for IE6 (and not IE7) using jquery.support?

My problem is that IE6 supports :hover psuedo-class only for anchor elements and IE7 does support it for all elements (as FF, Chrome, etc). So I want to do something special in case the browser does not support :hover for all elements... thus I need a way to test for this feature. (don't want to use jQuery.browser). Any ideas?

A: 

jQuery.support has no properties to detect :hover support http://docs.jquery.com/Utilities/jQuery.support

But probably you can simply use the hover() event http://docs.jquery.com/Events/hover

alex2k8
Yes, that is exactly my problem :), I want yo user the hover() event but only when is <IE6 if not use css:hover since it's much faster and realiable
Jaime
+9  A: 
<!--[if IE 6]>
  Special instructions for IE 6 here... e.g.
  <script>...hook hover event logic here...</script>
<![endif]-->
scunliffe
This is probably the best option, just wondering if anyone had another way to do it... since the jquery doc says "jQuery comes with a number of properties included, you should feel free to add your own.". Thank anyway
Jaime
+2  A: 

This is one example of where we should take a step back and ask why you're doing that.

Typically it's to create a menu. If so I highly suggest you save yourself some headaches and use a plug-in like superfish or one of the many alternatives.

If not I suggest you use the jQuery hover() event listener. For example:

$("td").hover(function() {
  $(this).addClass("hover");
}, function() {
  $(this).removeClass("hover");
});

will do what you want.

cletus
I'm doing a custom dropdown list with potentially a lot of items, so I want to use the jquery.hover event in case is <IE6 and use the css:hover for browsers that support it (since its faster). But you're probably right in saying that I should step back and re-think how I'm doing it.
Jaime
Is the speed of :hover an issue? To put it another way: is it worth the complexity cost of supporting a mixed solution?
cletus
Good question, probably not, it just feels a bit sluggish using the hover event
Jaime
Your requirements may vary but my general stance on IE6 is this: it just needs to be functional. It doesn't need to be perfect. It shouldn't have any glaring faults but it just needs to work.
cletus
@cletus: My problem is that 90% of my users use IE6 (SaaS enterprise App in Mexico) so if I don't work to make their experience work smoothly, I'm shooting myself in the foot.
Jaime
+20  A: 

While it's good practice to check for feature support rather then user agent, there's no simple way to check for something like support of a css property using JavaScript. I recommend you either follow the above posters suggestion of using conditional comments or use jQuery.browser. A simple implementation (not validated for performance or bugs) could look like this:

if ($.browser.msie && $.browser.version.substr(0,1)<7) {
  // search for selectors you want to add hover behavior to
  $('.jshover').hover(
    function() {
      $(this).addClass('over');
    },
    function() {
      $(this).removeClass('over');
    }
}

In your markup, add the .jshover class to any element you want hover css effects on. In your css, add rules like this:

ul li:hover, ul li.over { rules here }
Sasha Sklar
This is what I ended up with too. Just wanted to know if there was a better way to do it
Jaime
You really shouldn't use $.browser - it's deprecated.
Jonathan Sampson
@Jonathanl: Exactly... so what should I user for this?
Jaime
As I said, this is a case where pragmatism has to be balanced against best practices. You have a particular version of a particular browser that doesn't support a particular CSS feature. Check for ie6, apply your solution and move on. '\v'=='v' works fine btw.
Sasha Sklar
-1 This is deprecated behaviour and no longer supported in jQuery 1.3.
cletus
@cletus: Again... this is exactly the original question... since .browser is deprecated, how should you approach this?
Jaime
I have to agree with @jaimedp; deprecating $.browser without providing an adequate alternative feels like a step backwards. If you can't detect a css feature or bug with feature detection, you _have_ to do browser detection of some kind.
Adam Lassek
Goodness, the down voting is harsh. Fine, don't use $.browser, just good old conditional comments: <!--[if IE 6]> Special instructions for IE 6 here <![endif]-->
Jeff Meatball Yang
That was a joke, btw.
Jeff Meatball Yang
Sorry, couldn't resist: 'That was a joke, haha, fat chance"
Charlie Somerville
scunliffe's answer is better as it works for all IE6 users as opposed to simply IE6 users with Javascript enabled.
Andrew G. Johnson
Has it been removed, or just deprecated? Also, instead of the substr(), could parseInt($.browser.version, 10) be cleaner? They'll both return the same number, correct?
alex
TommyA
+7  A: 

Thickbox uses

if(typeof document.body.style.maxHeight === "undefined") {
 alert('ie6');
} else {
 alert('other');
}
Andrew
A: 

I would use Whatever:hover - http://www.xs4all.nl/~peterned/csshover.html

It uses behavior and works well for me.