Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:50:05+00:00 2026-06-14T17:50:05+00:00

I’m trying to implement a pseudo-class (in jQuery 1.8.3). Here’s the code: (function($) {

  • 0

I’m trying to implement a pseudo-class (in jQuery 1.8.3). Here’s 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 aim of this selector is to apply a style to “n” consecutive groups of elements, and could be used like so to color every 3 rows of a tbody (“this”) in an alternate color (classed with ‘alt’)

$(this).children(':visible').has('td').filter(':group(3)').addClass('alt')

This works well for one tbody. But if I’m iterating on several tbodies (with a ” $(‘..’).each” construct), index is not reset in-between.
This effect could be successfully achieved in jquery 1.6, since we naturally had (in the underlying “group” function parameters) the index within 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 could we achieve the same effects in jquery 1.8?

Thanks a lot for your insights!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:50:06+00:00Added an answer on June 14, 2026 at 5:50 pm

    There is a function called createPositionalPseudo in Sizzle, but it’s not exposed. By duplicating the function, I can actually use it and it worked. I simplified it to just:

    $.extend($.expr[':'], {
      group: $.expr.createPseudo(function(arg){
        return $.expr.createPseudo(function(seed, matches){
          for (var i=0; i<seed.length; i++) 
            if (i % (arg * 2) >= arg)
              matches.push(seed[i]);
          })
      })
    });
    

    I create a jsFiddle for test.

    I don’t know the inside of Sizzle, it seems seed is the list of elements for the pseudo filter to process, and matches is the list to return, indicating which pass the filter.

    The createPositionalPseudo also modifies seed, but the code above does not. It could cause problem, since I don’t know what’s inside, I am not sure. However, it runs okay in my test.

    The JavaScript in the jsFiddle contains a create_group_pseudo_safe, it’s not simplified. If there is any issue with simplified, that safe version function should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.