简体   繁体   English

如何在CSS中将CSS添加到特定tr的所有tds中?

[英]How to add CSS to all tds of a particular tr in jQuery?

I want to add a css {padding : 0px 8px 0px 2px} to all td's of a particular tr. 我想将css {padding : 0px 8px 0px 2px}到特定tr的所有td中。 tr is like this: $('#' + rowid) tr像这样: $('#' + rowid)

$('#' + rowid).find("td").css("padding", "0px 8px 0px 2px");

  • $('#' + rowid) gets the tr element. $('#' + rowid)获取tr元素。
  • .find("td") gets all td elements nested in your tr element. .find("td")获取嵌套在tr元素中的所有td元素。
  • .css("padding", "0px 8px 0px 2px") applies the relevant styles to your td elements. .css("padding", "0px 8px 0px 2px")将相关样式应用于您的td元素。

Try this: 尝试这个:

$('td', '#' + rowid).css('padding', '0px 8px 0px 2px');

Or better yet, put the padding in a class in your stylesheet and use addClass as it's a better separation of concerns. 或者更好的方法是,将padding放在样式表的类中,并使用addClass因为这样可以更好地分离关注点。

try this... 尝试这个...

$('.' + rowclass).find("td").css("padding", "0px 8px 0px 2px");

you can not use same id for more than one tag ,so you have to use class for that ,because tags can have same class but not same Id 您不能将同一个id用于多个标签,因此您必须为此使用class ,因为标签可以具有相同的类但不能具有相同的ID

Try like below... it will work 尝试如下...它将起作用

var ele = '#' + rowid;
$(ele + " td").css('padding', '10px 8px 0px 2px');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM