javascript - Select the second cell of each row in a table - Stack Overflow

I have a table and I was able to select the first cell of each row successfully, but I can not use the

I have a table and I was able to select the first cell of each row successfully, but I can not use the same code to select the second cell of each row. Please help me select and change the CSS of the second cell of each row. The reason that I don't use normal CSS is because these are future cells of a table.

$("#part_rows tr td:first-child").css("width","150px");

The above one works fine, but the following does not work.

$("#part_rows tr td:second-child").css("width","150px");

I have a table and I was able to select the first cell of each row successfully, but I can not use the same code to select the second cell of each row. Please help me select and change the CSS of the second cell of each row. The reason that I don't use normal CSS is because these are future cells of a table.

$("#part_rows tr td:first-child").css("width","150px");

The above one works fine, but the following does not work.

$("#part_rows tr td:second-child").css("width","150px");
Share Improve this question edited Jan 20, 2013 at 3:43 Metabble 11.8k1 gold badge17 silver badges29 bronze badges asked Jan 20, 2013 at 3:33 amirali shahinpouramirali shahinpour 1892 silver badges13 bronze badges 2
  • 1 $("#part_rows tr:nth-child(2)")?? – Derek 朕會功夫 Commented Jan 20, 2013 at 3:35
  • 3 0% accpet rate is not being very respectful of munity that helps you when you've asked 11 questions already – charlietfl Commented Jan 20, 2013 at 3:35
Add a ment  | 

3 Answers 3

Reset to default 7

Use the nth-child selector:

$("#part_rows tr td:nth-child(2)").css("width","150px");

If you plan to use jQuery, an hour spent browsing through the entire list of jQuery methods and selectors will save you a lot of time down the track...

"the reason that I dont use normal css because these are future cells of a table."

Did you try with "normal" CSS? I think you'll find that it works on elements that are added dynamically.

you are looking for the :nth-child selector

$("#part_rows tr").find('td:eq(1)')

In jQuery bining .find() - you can use 2 nice guys that do the job pretty well. You can take a look:

http://api.jquery./find/
http://api.jquery./eq/
http://api.jquery./eq-selector/

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信