I need to get the class name from a given <tr> tag, but am unable to do so.
<table cellpadding=5 cellspacing=5>
<tr id='cat_abc123' class='class_a'>
<td>foo</td>
<td><input type='checkbox' name='cb1' value='1' onClick="info(this, 'abc123')">
</tr>
</table>
<script language='javascript'>
function info(theElement, id)
{
tr_id = 'cat_' + id;
alert(tr_id + ' ' + document.getElementById(tr_id).class);
}
</script>
Working example: http://jsfiddle.net/rQpeu/
What am I missing?
Update
I was using the wrong descriptor - should use Classname. Thanks for the prompt responses everyone! Updated jsfiddle: http://jsfiddle.net/rQpeu/3/
element.class is incorrect.
You need to use element.className.
https://developer.mozilla.org/en-US/docs/DOM/element.className
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With