mootools / slick

Standalone CSS Selector Parser and Engine. An official MooTools project.
MIT License
149 stars 22 forks source link

WebKit QSA :nth-child is buggy unless there's a CSS rule that uses :nth-child #46

Closed cpojer closed 8 years ago

cpojer commented 13 years ago

http://jsfiddle.net/SubtleGradient/DWEUH/1/

Repost from lighthouse mootools-core:

this code

$$("#pt tr:nth-child(4n), #pt tr:nth-child(4n-1)").addClass("even");

fails on chromimum 5.0.342x on windows - whereas it works on IE8 and FF 3.6.12

test case: http://www.jsfiddle.net/mdtVB/9/ expected result: http://www.jsfiddle.net/mdtVB/10/

it is probably a browser error for this version of chrome but it may be worth looking into.

screenshot of bug: http://fragged.org/images/chrome-selector-bug.gif

subtleGradient commented 13 years ago

http://jsfiddle.net/SubtleGradient/DWEUH/1/ shows how adding a cssRule fixes this WebKit bug. That's currently the recommended workaround for people experiencing this bug, simple add an empty rule to your CSS that uses :nth-child.

However, I think we may be able to fix this for people automagically without too much effort, just need to make it work.

subtleGradient commented 13 years ago

Simplest feature test I could come up with

<iframe src="data:text/html;charset=utf-8,<li><li><script>alert(document.querySelectorAll(':nth-child(odd),:nth-child(odd)').length == document.querySelectorAll(':nth-child(odd)').length)</script>"></iframe>