cellSpacing
Property of dom/HTMLTableElementdom/HTMLTableElement
Syntax
var cellSpacing = table.cellSpacing;
table.cellSpacing = newCellSpacing;
Return Value
Returns an object of type NumberNumber
Examples
This example shows how to use the rows collection on the table object and the cells collection to insert a number into each cell of the table.
<!doctype html>
<html>
<head>
<script>
function numberCells() {
var count = 1;
var oTable = document.getElementById('oTable');
var rowsLength = oTable.rows.length;
for (var i=0; i < rowsLength; i++) {
var oCells = oTable.rows.item(i).cells;
var cellsLength = oCells.length;
for (var j=0; j < cellsLength; j++) {
oCells.item(j).innerHTML = count++;
}
}
}
</script>
</head>
<body onload="numberCells()">
<table id="oTable" border="1">
<tr><th> </th><th> </th><th> </th><th> </th></tr>
<tr><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td> </td><td> </td><td> </td><td> </td></tr>
</table>
</body>
</html>
Notes
A cells collection is comprised of th and td objects. When a cell spans multiple rows, that cell appears only in the cells collection for the first of the rows that the cell spans. If duplicate identifiers are found, a collection of those items is returned. Collections of duplicates must be referenced subsequently by ordinal position. Individual cells or an array of cells can be specified using a spreadsheet format. By specifying a colon-delimited string of the starting and ending cells, a cells collection can be retrieved from anywhere in the table. Specifying a particular cell with this format returns that object. The format of this string uses letters to indicate columns, starting with A, and numbers to indicate rows, starting with 1. A cells collection on a table row includes only the elements within that row if the vIndex string specifies a range of multiple rows using the spreadsheet format.
Related specifications
- DOM Level 2 HTML
- Recommendation
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]