Bug Tracker

Opened 13 years ago

Closed 13 years ago

#6543 closed bug (worksforme)

:visible and :nth-child selector

Reported by: coplas Owned by:
Priority: Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: visible nth-child Cc:
Blocked by: Blocking:


there is a problem with not visible elements (in my case TRs)

".tab tr:visible:even" works as expected, but "tr:visible:nth-child(2n-1)" not, it probably matches not only visible but all elements.

example: http://jsbin.com/ezocu

$(function() {

$("#t1 tr:eq(3)").hide();

$("#t2 tr:eq(3)").hide();

$(".tab tr:visible:even").addClass("even");

$(".tab tr:visible:nth-child(even)").addClass("even2");


Change History (1)

comment:1 Changed 13 years ago by dmethvin

Resolution: worksforme
Status: newclosed

Note that :eq and :even are 0-based and apply to the entire collection (with tr elements crossing two tables in this example ) whereas :nth-child is 1-based and applies to the sibling order regardless of visibility. Whether the tr is visible or not does not affect the :nth-child() selector; it is still that child whether it is visible or not. When I look at the markup in Firebug it doesn't seem that the hidden elements ever have even2 applied to them so it seems like the :visible:nth-child() combination worked properly.

Note: See TracTickets for help on using tickets.