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

  • SEARCH
  • Home
  • 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 8131587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:08:00+00:00 2026-06-06T09:08:00+00:00

I have a variable with a jQuery collection in it, like this: $collection =

  • 0

I have a variable with a jQuery collection in it, like this:

$collection = $(".example");

This gives me a bunch of nodes with the class “example”.

Now, I want to manipulate that collection and retain the results, which I thought would work like this:

$(".example", $collection).filter(":even").addClass("even");

Unfortunately, that doesn’t seem to work. Anytime I add an assignment to it, like this:

$collection = $(".example", $collection).filter(":even").addClass("even");

I get an empty collection.

The end result I want is to have all of the .example class even items in the $collection collection to have the class “even”. I don’t want to replace the contents of $collection with only the even .example elements.

  • 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-06T09:08:01+00:00Added an answer on June 6, 2026 at 9:08 am

    Try:

    $collection.filter(":even").addClass("even");
    or
    $(".example").filter(":even").addClass("even");
    

    When you defined $collection = $(".example"); what you were doing with
    $(".example", $collection) was looking for items with the example class inside of items with the example class.

    Better yet:

    $(".example:even").addClass("even");
    

    … would be even little more direct.

    Update:

    $collection.filter(":even").addClass("even");
    

    Doing this won’t overwrite the $collection variable.

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

Sidebar

Related Questions

I have declared this variable in jquery var enabled = false; I want to
I have a jQuery variable like this: var variable = $j(this).val(); Where $j(this) is
I have a jQuery variable merImg like this var merImg = '<a href=http://xxx.com><img src=http://om.com/pion/thumbnail/11x65/aa/img.jpg
I have a jquery variable that isnt working and it's most likeley because i
So I have captured the ID of an image in a jquery variable like
I have a jQuery variable. It's a text string. I want to create a
Let's say I have a template like this <script id=rowTemplate type=text/x-jquery-tmpl> <tr> <a href=${
I have problem on passing jquery variable on codeigniter controller. actually i want to
I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I have this jQuery snippet, I have stored the variables to highlight them. var

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.