Skip to content

jQuery Index Inconsistency

The jQuery :nth-child selector has an "index" argument which is 1-based. But the jQuery "index" method, which is arguably the converse of the selector, returns a 0-based result. This is very easy to work around once you’re aware of it, but it’s surprising in a library which is, generally, designed both well and consistently.

{ 1 } Comments

  1. Corwin | May 18, 2009 at 10:35 am | Permalink

    Yep, banged my head over this too :) But I guess they had no choice, as the CSS 3 specification says nth-child indexing is 1-based: http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#nth-child-pseudo

Post a Comment

Your email is never published nor shared. Required fields are marked *

Bad Behavior has blocked 713 access attempts in the last 7 days.

Close