soham
soham

Reputation: 1668

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. tr is like this: $('#' + rowid)

Upvotes: 0

Views: 2184

Answers (4)

Sagar Hirapara
Sagar Hirapara

Reputation: 1697

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

Upvotes: 1

Pandian
Pandian

Reputation: 9126

Try like below... it will work

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

Upvotes: 1

Curtis
Curtis

Reputation: 103348

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

  • $('#' + rowid) gets the tr element.
  • .find("td") gets all td elements nested in your tr element.
  • .css("padding", "0px 8px 0px 2px") applies the relevant styles to your td elements.

Upvotes: 4

Rory McCrossan
Rory McCrossan

Reputation: 337560

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.

Upvotes: 1

Related Questions