Nunja, dein Script funktioniert einwandfrei, sobald ich aber etwas ändern will - z.B. statt auf den Header klicken einen Link einfügen, dann ändere ich auch entsprechend die Variable table, aber dann klappts bei mir wieder nicht. Irgendwie komm ich überhaupt nicht klar damit.
<table>
<thead>
<tr>
<th><a href="javascript:toggle(this)">Header</a></th>
</tr>
</thead>
<tbody style="display: none;">
<tr>
<td>Text</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function toggle(cell) {
var table = cell.parentNode.parentNode; //Ein zweites Mal, weil ja der a-Tag ein Child von th ist...
while (table && (table.nodeName != 'TABLE')) {
table = table.parentNode;
}
if (table) {
var tbody = table.getElementsByTagName('tbody')[0];
if (tbody) {
tbody.style.display = (tbody.style.display == 'none') ? 'table-row-group' : 'none';
}
}
}
</script>
Wahrscheindlich mache ich irgendeinen Denkfehler. Herzlichen Dank trotzdem!