Reputation: 13699
The reason I want to do this is because I am having trouble changing the classes of td elements in certain browsers. I am wondering if it is possible to simply replace the entire element, caveats, code, and suggestions are all appreciated.
Upvotes: 0
Views: 2918
Reputation: 999
You can use jQuery to easy remove some tds and replace them with new tds, i.e.:
$("td").remove();
$("tr").append("HTML CODE");
Upvotes: 1
Reputation: 147483
You can replace a table cell with another table cell just like any other element:
var td = <reference to td element>;
var newTd = document.createElement('td');
td.parentNode.replaceChild(newTd, td);
If you just want to add or assign a new class value, see qwertymk's answer.
Upvotes: 2
Reputation: 35304
Did you try td.className += ' newClass'
to add a class or td.className = 'newClass'
to assign it just one class?
Upvotes: 0