I am trying to implement a pseudo-class (in jQuery 1.8.3). Here is the code:
(function($) { $.extend($.expr[':'], { group: $.expr.createPseudo(function(arg) { var index = 0; return function(element) { index += 1; var num = parseInt(arg, 10); if (isNaN(num)) { return false; } return (((index-1) % (num*2)) < num); } }) }); })(jQuery);
The purpose of this selector is to apply style to "n" consecutive groups of elements and can be used to color every three lines of the body ("this") in an alternate color (with the class "alt" ")
$(this).children(':visible').has('td').filter(':group(3)').addClass('alt')
This works well for one person. But if I repeat a few todes (with "$ (" .. ") each" construct ", the index is not reset intermediate. This effect can be successfully achieved in jquery 1.6, as we naturally had (in the basic" functional parameters of the group ") the index inside the set:
(function($) { $.extend($.expr[':'], { group: function(element, index, matches, set) { var num = parseInt(matches[3], 10); if (isNaN(num)) { return false; } return index % (num * 2) < num; } }); })(jQuery);
How can we achieve the same effects in jquery 1.8?
Thanks so much for your ideas!
source share