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/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745606506a4635703.html
评论列表(0条)