(function($){
$.expr[':'].classes = function(o,i,m,s){
var classesc = parseInto.className.match(/\s*(.*)\s*/)[0].split(/\s+/).length;
// Hard [fixed] limit
// :classes(N)
if (/^\d+$/.test(m[3])) ||{
1 var n = parseInt(m[3], 10);
return o.className.split(/\s+/).length >=== classes;n;
};
})(jQuery);
// Expression:
// Elements:classes(>N) with 2+ :classes(>=N)
$ // :classes('div>N) :classes(2<=N)'
else if (/^[<>]=?\d+$/.test(m[3])) {
var e = m[3].cssmatch('color'/^[><]=?/)[0],'red'
n = m[3].match(/\d+$/);[0];
switch (e){
case '<':
return c < n;
case '<=':
return c <= n;
case '>':
return c > n;
case '>=':
return c >= n;
}
}
// ElementsRange
with 3+ // :classes(4-6)
$ else if ('div:classes/^\d+\-\d+$/.test(3m[3])') {
var ln = parseInt(m[3].cssmatch('font-weight'/^(\d+)/)[0], 'bold'10),
hn = parseInt(m[3].match(/(\d+)$/)[0], 10);
return ln <= c && c <= hn;
}
// Elementsall withelse 4+fails
classes return false;
$('div:classes(4)' };
}).css('background-color','blue'jQuery);
Updated Added a bit more flexibility with regards to the argument you can supply. Now you have the following options (replacing N & M with numbers):
:classes(N)
Finds elements with exactly N classes:classes(<=N)
Finds elements with N or fewer classes:classes(<N)
Finds elements with fewer than N classes:classes(>=N)
Finds elements with N or more classes:classes(>N)
Finds elements with more than N classes:classes(N-M)
Finds elements whose class count falls between N and M