Nk SP
Nk SP

Reputation: 856

Get table column by Jquery

I need to make "bold" the second column of this html table:
http://jsfiddle.net/beKC4/4/

How can I do using JQuery?
I tried this but is not working:

$("h3.ms-standardheader").children("td").text("<b>"+this.text()+"</b>")

Upvotes: 0

Views: 2111

Answers (4)

aahhaa
aahhaa

Reputation: 2275

http://jsfiddle.net/b4AwC/

I would use nthchild selector, if you want ever other one bold you can put in even or odd I hope this help

$("tr td:nth-child(2)").css({"color":"red"});
$("tr td:nth-child(even)").css({"background":"grey"});

Upvotes: 0

Alex Char
Alex Char

Reputation: 33228

You can use this. Create a css class and add this class with js using :nth-child(). Think is simplier.

css

.bold{
    font-weight: bold;
}

js

$('table td:nth-child(3)').addClass('bold');

fiddle

Upvotes: 0

Grasper
Grasper

Reputation: 1313

you can also use css

see here http://jsfiddle.net/beKC4/6/

table tr td:nth-child(3){
    font-weight:bold;
}

Upvotes: 4

Anton
Anton

Reputation: 32591

Use .html() instead

$(".ms-standardheader").closest('tr').find("td").html(function () {
    return "<b>" + $(this).text() + "</b>"
});

Also, the selector is incorrect, you need to use closest, then find the <td>

DEMO

Or if you don't want ms-standardheader to also get <b> you can use siblings()

$(".ms-standardheader").closest('td').siblings("td").html(function () {
    return "<b>" + $(this).text() + "</b>"
});

DEMO

Upvotes: 2

Related Questions