开发者

jQuery pseudo-selector ":not" IE7 not working?

Using Firebug Lite in IE 7, with jQuery 1.4.4. I'm trying to grab all the ".step" <div/> elements that are not the first one (there a开发者_如何学Cre 2 or 3 now, but assume an arbitrary amount of steps). Works in FF and Webkit, but noticed the same selector of :not with :first does not select the same items in IE7. jQuery bug? Should this work? Can you suggest an alternative way to select these items?

# Firebug Lite console
>>> $('.step')
[div#step_1.step, div#step_2.step, div#step_3.step]
>>> $('.step:first')
[div#step_1.step]
>>> $('.step:not(:first)')
[div#step_1.step, div#step_2.step, div#step_3.step]


This isn't an answer to the IE7 issue, but it is a workaround, and probably a better way to do it overall.

Instead of:

$('.step:not(:first)')

do this:

$('.step').slice(1);

Now you're using a simple selector that is valid for querySelectorAll, and simply paring it down to all but the first match.

Overall it should perform better for you.


EDIT:

There does seem to be an open bug with regard to :not(:first) in IE 7.

Here's the link: http://bugs.jquery.com/ticket/4028


You could use

$('.step:gt(0)')

don't have an IE7 handy to test at the moment though


The .not() method is recommended over the :not pseudo-class selector in the jQuery documentation for readability, but :not also has terrible performance consequences. Omitting tag-names does as well in many cases. Testing in IE8, I found the .not() method about thirty-four times faster than the :not pseudo-class selector.

I concur with user113716 that the .slice method is probably best here, but for those having trouble with :not in a similar situation, I would suggest something like this:

$('div.step').not('div:first')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜