On 12/14/06, Yehuda Katz <
wycats@...> wrote:
> If
that was the case, jQuery("#main a").filter(function() { return false;
}) would return nothing. But it doesn't. It returns the original group
of elements. At least for me.
Hm... I also tested this and filter didn't prune the list with my function returning false.
Here's the filter function out of 1.0.3 which checks if t is a function and pushes the result of
jQuery.grep(this, t) onto the stack.
filter: function(t) {
return this.pushStack(
*SNIP*
typeof t == "function" &&
jQuery.grep( this, t ) ||
jQuery.filter(t,this).r, arguments );
},
Now in the grep function it operates on the list of elements in elms. It calls the function we defined (fn) and if fn returns false it shouldn't add them to the result array.
grep: function(elems, fn, inv) {
*SNIP*
var result = [];
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0; i <
elems.length; i++ )
if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
result.push( elems[i] );
return result;
},
Am I missing something here?
Cheers,
-js
_______________________________________________
jQuery mailing list
discuss@...
http://jquery.com/discuss/