$('tr:even').addClass('alt');
why does $('tr:even').addClass('a开发者_Go百科lt');
select from the 1st row
and $('tr:nth-child(even)').addClass('alt');
selects from the 2nd row ?
It's because :even gets even elements using 0-based indexing and :nth-child() uses 1-based indexing.
maybe the selector looks at the index and nth-child(even) looks at the length? Seems like an oversight.
got it! :odd and :even selectors use Javascript native zero based numbering. so the first row counts as 0(even)
精彩评论