tags:

views:

35

answers:

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

+2  A: 

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.

Nick Craver
i was looking for something like this only, i think we cannot pass an object to filter fn as third paramneterstill this code solved my problem thanx.
Praveen Prasad