开发者

Are these jQuery expressions equivalent?

I'm wondering if these two expressions are equivalent, because if they are, it would make this much easier.

$('div', this).filter(':not(.trigger)')...

$('div:not([class*=trigger])', this)...

开发者_StackOverflow

(this providing a context under which to look for the specified div)


No.

Version 1 takes all divs without the class trigger.

Version 2 takes all the divs where the attribute class contains the text trigger. This means a div with the class mytrigger will be a match.

Selectors

EDIT

With your updated question this would be the equivalent to the first version.

$('div:not(.trigger)', this)


They're not essentially the same. The second also filters out all div's which have a class which contains "trigger" in the name, thus also e.g. "anothertrigger" and "triggerfoo".

You can also use

$('div:not(.trigger)', this)...

which is imho much clearer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜