Satch3000
Satch3000

Reputation: 49384

CSS Remove or rename a class on first-child

I have a table TD which is created dynamically. All the TDs created have a CLASS. I have set the first-child Display to NONE. I just need to remove or rename this class just on the first child. Does anyone have any ideas on how I could do this please?

Thanks

Upvotes: 3

Views: 8677

Answers (4)

scrappedcola
scrappedcola

Reputation: 10572

$(".tdClass").get(0).className = "newClassName"

Should do what you want. or

$($(".tdClass").get(0)).removeClass("tdClass");

Upvotes: 1

odrm
odrm

Reputation: 5259

$(#tableid td:first-child').removeClass('oldClass').addClass('newClass'); will work, provided that you substitute to correct id for #tableid.

Upvotes: 0

steve_c
steve_c

Reputation: 6255

$('table td:first').removeClass('className')

or

$('table td:first').toggleClass('className')

Upvotes: 9

Rory McCrossan
Rory McCrossan

Reputation: 337560

From the jQuery documentation - http://api.jquery.com/first-child-selector/

$(".myTable TD:first-child").removeClass("old-class-name").addClass("new-class-name");

or

$(".myTable TD:first-child").attr("class", "old-class-name");

Upvotes: 0

Related Questions