1
     1. jQuery.expr[':'].aFilter =
        function(elem, index, match){

                return true; // Return true/false as per need

        };

        $('div.red').filter(':aFilter').doSomething();

i want pass some custom arguments to "jQuery.expr[':'].aFilter" function, is it possible to do it

Praveen Prasad
  • 31,561
  • 18
  • 73
  • 106

1 Answers1

2

In your case if someone did $('div.red').filter(':aFilter(textHere)') You would use match[3] in your function to do what you wanted with the textHere string.

Here's an example I use for case-insentitive contains search:

jQuery.expr[':'].Contains = function(a, i, m) { 
    return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; 
};

The use is: $(":Contains(Text To Match)");
In this case m[3] ("Text To Match") is the passed param I care about.

You can find a full list of the parameters in this answer.

Community
  • 1
  • 1
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • i was looking for something like this only, i think we cannot pass an object to filter fn as third paramneter still this code solved my problem thanx. – Praveen Prasad Mar 18 '10 at 18:53