views:

98

answers:

2

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)...

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

+3  A: 

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)
ChaosPandion
Can you look at it again? I forgot the `:not()` part in the second version...
Alexsander Akers
Alexsander: if you're looking for a statement equivalent to the first one, you can use `$('div:not(.trigger]))'`.
Matt Ball
+2  A: 

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.

BalusC
He accepted your answer before you corrected it. :(
ChaosPandion
Maybe because I initially did give the clearer example. Sorry about that. Your answer was by the way initially also confusing because I didn't see that the OP edited the question.
BalusC