javascript - Traversing a table column -jQuery - Stack Overflow

Given a 3 by 3 table, i want to add a class to allthe cells of 3rd column .I have tried doing $( 

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 badges
Add a ment  | 

2 Answers 2

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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745606506a4635703.html

相关推荐

  • javascript - Traversing a table column -jQuery - Stack Overflow

    Given a 3 by 3 table, i want to add a class to allthe cells of 3rd column .I have tried doing $( 

    3小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信