Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#8542 closed bug (worksforme)

nth-child in WebKit returns wrong count of elements

Reported by: [email protected] Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description

I've got some strange issue.

I wanted to use :nth-child() to select 4 last children out of my selection: jsfiddle.net/vsRj3/3/ But it returns wrong count of elements, in this case 3, but on my production site an empty list. Strange enough, when I leave even number of selectors, it returns ok, but odd number, it returns nothing.

On the other hand, by using :eq() : jsfiddle.net/vsRj3/4/ works ok.

It seems there's a bug concerning :nth-child.

Checked on Chrome 10.0.648.134 and Safari 5.0.4

Thanks for help!

Change History (6)

comment:1 Changed 11 years ago by Rick Waldron

Component: unfiledselector
Priority: undecidedlow
Resolution: worksforme
Status: newclosed

Looks like it's producing the correct counts for me:

http://jsfiddle.net/rwaldron/nHDbT/1/

comment:2 Changed 11 years ago by [email protected]

What version of Chrome did you check?

comment:3 Changed 10 years ago by Ceriel Jacobs <[email protected]…>

This :nth-child() with webkit browsers (Safari/Chrome) problem still exists. I spotted this when trying to hide lines of input fields in a form.

See http://jsfiddle.net/ZAJfh/ Row 1 is shown = ok = Firefox 7.0.1, Opera 11.52, Explorer 7 Row 1+3 are shown = not ok = Safari 5.1, Chrome 16.0.912.15

Workaround Add a unique (dummy) class to each element where applying :nth-child() to. The class needs to be unique for each element, an identical class doesn't work. See http://jsfiddle.net/HVYe3/

This might be helpful for readers of http://api.jquery.com/nth-child-selector/

comment:4 Changed 10 years ago by Rick Waldron

#10620 is a duplicate of this ticket.

comment:5 Changed 10 years ago by dmethvin

This is most likely a bug in the implementation of querySelectorAll in Chrome, so it would be more appropriate to report it to them using a simple non-jQuery example. Given their development pace it would be inefficient/impractical for us to try and fix this with some sort of "look for the bug, scan every selector string, and avoid using querySelectorAll" approach.

These are likely to be related:

https://github.com/mootools/slick/issues/46

http://code.google.com/p/chromium/issues/detail?id=69400

comment:6 Changed 10 years ago by anonymous

It seems to trigger when using multiple selectors. Single selector nth-child works fine.

Note: See TracTickets for help on using tickets.