Is it possible to change the CSS class of an entire table row using JavaScript?

Recommended Answers

All 2 Replies

Yes.

To assign a class

obj.className = 'myclass'

To add a class

obj.className += ' myclass' // NOTE the leading blank

Existing class(es) can also be removed.

To refer to the row in question use something like

var obj = document.getElementById('myspecialrow')

or in the more general case

var obj = document.getElementById{'myspecialtable'}.rows[myspecialrownum] // where "myspecialrownum" is the index of 'myspecialrow', starting from zero

For a completely different approach, this post http://www.daniweb.com/forums/post1213631.html#post1213631 shows how to manipulate class declarations (which makes it possible to change the appearance of multiple rows all at once).

fxm...thanks for the tip!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.