views:

194

answers:

2

I am trying to have a jQuery selector to select a element only if its children are not animated.

I tried:

var articalLink =  $(".navArticals").filter($(this).children("ul:not(':animated')"));

It doesn't work

It turned out that only this works

var articalLink =  $(".navArticals").filter(function() {
   var filtered = $(this).children().not(":animated");
   return filtered
 });

Is there a way to select without the function inside .filter() ?

+3  A: 

$(".navArticals").filter(":not(:has(:animated))")

or

$(".navArticals:not(:has(:animated))")

filter requires a string or a function, not a jQuery object. But you could just weed out the elements with your initial selector.

geowa4
FYI I tried Both, they don't select what i want. they don't filter out if its children are animated, anyway thanks.
adardesign
it really should.
geowa4
+3  A: 

I don't think so in this instance as you need to apply the filter based on the children of each element within the wrapped set. You can shorten the filter slightly though to

// you don't necessarily need to assign to a variable,
// just depends what you want to do with it
var articalLink = $(".navArticals").filter(function() {
   return $(this).children().not(":animated");
});

the filter function is a predicate (an expression that evaluates to true or false) to filter out those elements in the wrapped set whose children are animated.

Russ Cam