...

View Full Version : Setting colspan at runtime



dragon6158
05-05-2008, 09:22 PM
Hello,
I want to set the colspan of a header in a table to equal the number of columns in a datarow under it at runtime. Is this possible and how would I do it?

Thanks,
Don

fside
05-06-2008, 03:54 AM
Styles might do it. Of course, only a suggestion, since this won't work in IE6, which is still widely used (unfortunately).



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<style>

#tabl {
display: table;
width: 40&#37;;
}

div >div {
display: table-caption;
background: #ffa;
font-variant: small-caps;
font-size: 110%;
padding: 0.3em;
text-align: center;
}

div >span {
display: table-cell;
padding: 0.5em;
background: #aff;
border-left: 1px solid #000;
}

BR {
display: table-row;
}

</style>

</head>

<body>

<div id="tabl">
<div>Header</div>
<span>data1</span>
<span>data2</span>
<span>data3</span>
<span>data4</span>
<span>data5</span>
<span>data6</span>
<span>data7</span>
<span>data8</span><br>
<span>data9</span>
<span>data10</span>
<span>data11</span>
<span>data12</span>
<span>data13</span>
<span>data14</span>
<span>data15</span>
<span>data16</span>
</div>

<script>


</script>

</body>
</html>


If on the other hand you need a table, you could make your caption a - caption - or a header - TH. Table -> TH -> TR . . td /td /TR, like that. And you could give the TH its own id and use getElementById, or if it's just the one table, a getElementsByTagName("th")[0] . You can then directly change its colspan, if you've counted the number of columns.

In IE6, though, remember that 'colspan' is a 'camel-case' name. So not, "colspan", but "colSpan".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum