Bug Tracker

Opened 13 years ago

Closed 13 years ago

#1727 closed bug (fixed)

:nth-child(An+B) incompatibility with CSS3

Reported by: amachang Owned by: davidserduke
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:

Description

Code:

<style> ul > li { display: none } </style>
<script src="jquery.js"></script>
<script>$(function() {

    $('ul > li:nth-child(3n+1)').css('display','block');

})</script>
<style>

    ul > li:nth-child(3n+1) { display: block } 

</style>

<ul>
 <li>CSS3 select this element.</li>
 <li>jQuery select this element.</li>
 <li></li>
 <li>CSS3 select this element.</li>
 <li>jQuery select this element.</li>
<ul>

Patch:

Index: selector.js
===================================================================
--- selector.js (revision 3472)
+++ selector.js (working copy)
@@ -372,7 +372,7 @@
                                        if ( first == 1 ) {
                                                if ( last == 0 || node.nodeIndex == last )
                                                        add = true;
-                                       } else if ( (node.nodeIndex + last) % first == 0 )
+                                       } else if ( (node.nodeIndex - last) % first == 0 )
                                                add = true;
 
                                        if ( add ^ not )

Attachments (2)

1727.diff (1.4 KB) - added by davidserduke 13 years ago.
patch
jquery_test.html (1.5 KB) - added by davidserduke 13 years ago.
test cases

Download all attachments as: .zip

Change History (5)

comment:1 Changed 13 years ago by davidserduke

Going over the way the selector works in CSS3 here

http://www.w3.org/TR/css3-selectors/#nth-child-pseudo

I noticed a few other issues. Negative numbers didn't work and (n+1) was giving (1) instead of (n). Those are fixed in the patch as well.

Changed 13 years ago by davidserduke

Attachment: 1727.diff added

patch

Changed 13 years ago by davidserduke

Attachment: jquery_test.html added

test cases

comment:2 Changed 13 years ago by brandon

need: ReviewCommit
Owner: set to davidserduke

comment:3 Changed 13 years ago by davidserduke

Resolution: fixed
Status: newclosed

Fixed in [3836].

Note: See TracTickets for help on using tickets.