tags:

views:

49

answers:

4

I know that I can get the class name from a table cell if I have the id of the cell, i.e.

scr = document.getElementById(cellid);

classN = scr.className;

However I want to get the class name from a table with potentially 1000+ cells. Can I do this without id'ing every cell?

Any help would be appreciated.

Thanks

+1  A: 

You could do

<script type="text/javascript">
    function travel(src) {
        src.setAttribute("class", "style_notEmptyOrWhateverTheNewStyleIsCalled");
    }
</script>

<td class='style_empty' onClick='javascript:travel(this)'>no Data</td>
jitter
every empty cell in my table would look like this <td class = 'style_empty' onClick='travel()' > No Data </td>on click I want to change the class of the cell clicked
Mick
+1  A: 

Well, sure. document.getElementById is just a shortcut to pull a node from the DOM through it's ID. You're free to find these nodes by any other method; i.e. find the table node, then recurse through it's children finding every td. You might like getElementsByTagName for this purpose - see the W3C DOM documentation for more on this.

Adam Wright
A: 

have you tried just giving the table an id and getting it that way?

<table id='someTableId' class='whatever'>...

scr = document.getElementById('someTableId');

classN = scr.className;
Joseph
A: 

Instead of setting a thousand handlers on the cells, why not set just one on the table?

thetable.onclick= function(e){
 e= window.event || e;
 var who= e.srcElement || e.target;
 var t= who.tagName;
 if(t== 'TD' || t== 'TH'){
  //do whatever to the cell
 }
 //finish up with
 if(e.stopPropagation) e.stopPropagation();
 else e.cancelBubble= true;
}
kennebec