Properti HTMLTableCellElement.colSpan
menetapkan atau mengembalikan atribut COLSPAN elemen TH/TD HTML.
Sintaks:
tableCellObj.colSpan = value
tableCellObj.colSpan
value adalah number (long) yang sedikitnya satu digit di dalam cakupan 0-9.
Contoh di bawah ini mengembalikan nilai atribut COLSPAN:
<TABLE WIDTH="50%" BORDER="1">
<TR>
<TH COLSPAN="2">row 1, header cell 1</TH>
</TR>
<TR>
<TD>row 2, cell 1</TD>
<TD>row 2, cell 2</TD>
</TR>
<TR>
<TD>row 3, cell 1</TD>
<TD>row 3, cell 2</TD>
</TR>
</TABLE>
<SCRIPT TYPE="text/javascript">
var tableObj = document.getElementsByTagName("table")[0];
var myCell = tableObj.rows[0].cells[0];
alert(myCell.colSpan); // 2
</SCRIPT>
Contoh di bawah menetapkan atribut SPAN:
<TABLE WIDTH="50%" BORDER="1">
<TR>
<TH>row 1, header cell 1</TH>
</TR>
<TR>
<TD>row 2, cell 1</TD>
<TD>row 2, cell 2</TD>
</TR>
<TR>
<TD>row 3, cell 1</TD>
<TD>row 3, cell 2</TD>
</TR>
</TABLE>
<SCRIPT TYPE="text/javascript">
var tableObj = document.getElementsByTagName("table")[0];
var myCell = tableObj.rows[0].cells[0];
myCell.colSpan = 2;
</SCRIPT>