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 7565305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:07:17+00:00 2026-05-30T14:07:17+00:00

Ok another dumb jQuery question… The not selector in jQuery is giving me problems.

  • 0

Ok another dumb jQuery question…

The not selector in jQuery is giving me problems. I’m trying to select all but the first element having a given class toggle-button. But I can have this dialogue with the console…

? $('.toggle-button').length
4
? $('.toggle-button:not(:eq(0))').length
4

No difference. But…

? $('div').length
23
? $('div:not(:eq(0))').length
22

What gives, Resig?

Why does the not selector have different behaviour when applied to a class (seemingly) – and how can I do the select I want in the most idiomatic jQuery way?

:not(:first) does the same thing…

UPDATE

Thanks for all responses. This looks to be a bug in the jQuery/IE partnership.

Solutions…

$('.toggle-button').filter(':gt(0)')

$('.toggle-button').not(':first')

$('.toggle-button').slice(0);

…and no doubt many more. I’ll leave it to the crazies to figure which is best 😀

  • 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-05-30T14:07:18+00:00Added an answer on May 30, 2026 at 2:07 pm

    Any non-CSS filtering/selecting should be done through jQuery methods, as it means that jQuery is unable to use CSS to speed up the selector. It tries to use the native CSS support in the browser but if you use :not or :eq etc, it has to use its own parsing system which is slower.

    The air-quotes “correct” way is this:

    $('.toggle-button').filter(':gt(0)').length;
    

    As to why the :not behaves differently, I’m not sure. I’ll keep thinking, and if I get a lightbulb, I’ll update this answer 🙂


    Edit: It looks like its some browser-specific quirk – I’ve just done

    • $('.prettyprint').length – 3
    • $('.prettyprint:not(:eq(0))').length – 2
    • $('.question-header').length – 1
    • $('.question-header:not(:eq(0))').length – 0

    For this page, at the time I did them, those numbers were right and predictable. Double check your code for silly typos, and that kind of thing, because it looks to be working OK here.


    Edit Edit: It’s an IE8 bug, presumably to do with the CSS selection engine it uses. See http://jsfiddle.net/5gSxP/2/ for a rundown of the 3 selection methods, the first one fails in IE8 but the one in this answer works OK.

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

Sidebar

Related Questions

First, I am NOT trying to spur yet another debate about LINQ vs. stored
This is a very dumb question, I'm sure. But is it possible for another
I feel my question is pretty dumb, or another way to put it is
This is probably another dumb question.... I'm new to ASP.NET MVC and I'm following
I'm sure I have something dumb wrong, but I'm trying to pass the data
The question is quite dumb, but I need to do it in a very
This must be a dumb question, but I cannot figure it out. I also
I'm sure many will consider this a dumb question but I can't find a
OK - I feel pretty dumb asking such a basic question, but hey. I'm
This is really a dumb newbie question, but I am still learning the ropes

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.