admin管理员组文章数量:1023764
Given a 3 by 3 table, i want to add a class to all the cells of 3rd column .
I have tried doing
$( 'td:eq(3)' ).addclass('special');
$( 'td:eq(5)' ).addclass('special');
$( 'td:eq(8)' ).addclass('special');
but the problem is writing 3 lines of code. Can a single line of code do it ?
Given a 3 by 3 table, i want to add a class to all the cells of 3rd column .
I have tried doing
$( 'td:eq(3)' ).addclass('special');
$( 'td:eq(5)' ).addclass('special');
$( 'td:eq(8)' ).addclass('special');
but the problem is writing 3 lines of code. Can a single line of code do it ?
Share Improve this question asked Feb 11, 2012 at 15:50 HalfWebDevHalfWebDev 7,66814 gold badges71 silver badges110 bronze badges2 Answers
Reset to default 7$('tr > td:nth-child(3)').addClass('special');
DEMO: http://jsfiddle/TcQex/
DOCS: http://api.jquery./nth-child-selector
$("td:nth-child(3)").addClass('special');
good article about nth-child -
http://css-tricks./how-nth-child-works/
Given a 3 by 3 table, i want to add a class to all the cells of 3rd column .
I have tried doing
$( 'td:eq(3)' ).addclass('special');
$( 'td:eq(5)' ).addclass('special');
$( 'td:eq(8)' ).addclass('special');
but the problem is writing 3 lines of code. Can a single line of code do it ?
Given a 3 by 3 table, i want to add a class to all the cells of 3rd column .
I have tried doing
$( 'td:eq(3)' ).addclass('special');
$( 'td:eq(5)' ).addclass('special');
$( 'td:eq(8)' ).addclass('special');
but the problem is writing 3 lines of code. Can a single line of code do it ?
Share Improve this question asked Feb 11, 2012 at 15:50 HalfWebDevHalfWebDev 7,66814 gold badges71 silver badges110 bronze badges2 Answers
Reset to default 7$('tr > td:nth-child(3)').addClass('special');
DEMO: http://jsfiddle/TcQex/
DOCS: http://api.jquery./nth-child-selector
$("td:nth-child(3)").addClass('special');
good article about nth-child -
http://css-tricks./how-nth-child-works/
本文标签: javascriptTraversing a table column jQueryStack Overflow
版权声明:本文标题:javascript - Traversing a table column -jQuery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745606504a2158758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论