开发者

$('tr:even').addClass('alt');

开发者 https://www.devze.com 2022-12-18 07:10 出处:网络
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

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消