admin管理员组文章数量:1405618
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
3 Answers
Reset to default 7Use 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/
本文标签: javascriptSelect the second cell of each row in a tableStack Overflow
版权声明:本文标题:javascript - Select the second cell of each row in a table - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744308031a2599894.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论