In jQuery, you can run a selector where every element is run through a function you define, like this (totally contrived example):
jQuery.expr[':'].AllOrNothing= function(a,i,m){
// a is the thing to match, m[3] is the input
if(m[3] === "true"){
return true;
} else {
return false;
}
};
Then you can use it like:
$("div:AllOrNothing(" + true + ")"); //returns all divs
$("div:AllOrNothing(" + false + ")"); //returns nothing
Is it possible to pass an anonymous function instead of calling jQuery.expr[:].Name= ?
Edit
I’m envisioning something chainable like the following:
$("div").filterByFunction(function(a,i,m){ ... })
It sounds like you just want to use the built-in
.filter()method and pass it a custom function that examines sibling elements to decide whether to return true or false and then hide the remaining elements.