I will like to use javascript GetElementById in a PHP for loop whereby the ids are generated as the loop executes and not fixed ids as in the example below. Therefore function displayRow() once executed will collapse all cells with ids variably assigned on looping. thus i will have $i or a variable id instead of captionRow, captionRow2 etc.
Expand|Select|Wrap|Line Numbers
- function displayRow(){
- var col = document.getElementById("captionRow");
- if (col.style.display == '') col.style.display = 'none';
- else col.style.display = '';
- var col2 = document.getElementById("captionRow2");
- if (col2.style.display == '') col2.style.display = 'none';
- else col2.style.display = '';
- var col3 = document.getElementById("captionRow3");
- if (col3.style.display == '') col3.style.display = 'none';
- else col3.style.display = '';
- }
<table width="300" border="1">
<th class = 'hr' id="captionRow">TH-1</th><th>TH-2</th><th>TH-3</th></tr>
<tr><td class = 'hr' id="captionRow2">cell-11</td><td>cell-12</td><td>cell-13</td></tr>
<tr><td class = 'hr' id="captionRow3">cell-21</td><td>cell-22</td><td>cell-23</td></tr>
</table>
<p><button onclick="displayRow()" >Show / Hide</button></p>
</body>
</html>
[/HTML]
thanks in advance