Ravi
Ravi

Reputation: 4095

jQuery selector for all the cols except the first col on a table

I want to apply right alignment for all the columns except for the first column.

I wrote the following, but which is working fine. But how can i combine these to statements in to one line.

$("table.ftable tr:gt(0)").css("text-align", "right");
$("table.ftable td:first-child").css("text-align", "left");

Any Ideas..?

Upvotes: 1

Views: 361

Answers (4)

Richard Andrew Lee
Richard Andrew Lee

Reputation: 1177

try using CSS in a style sheet. avoid js to css at all costs if you can!.. an accumulation of these will make your app slower.

http://jsfiddle.net/KCb4K/2/

table td {
   text-align:right;
}

table tr td:first-child {
    text-align: left !important;
}

http://www.w3schools.com/cssref/sel_firstchild.asp

Upvotes: 3

v42
v42

Reputation: 1425

Here it is:

$(".ftable td:gt(0)").css("text-align", "right");

http://jsbin.com/ivegoh/edit

Upvotes: 0

cvsguimaraes
cvsguimaraes

Reputation: 13260

table.ftable tr:nth-child(n+1);

Upvotes: 0

Tushar Ahirrao
Tushar Ahirrao

Reputation: 13155

Try this :

$("table td:first").css("text-align", "left");

Upvotes: 0

Related Questions