Latest web development tutorials

HTML DOM TableHeader colSpan property

TableHeader Object Reference TableHeader objects

Examples

Change the number of columns spanned by a cell:

document.getElementById("myTh").colSpan="1";

try it"

Definition and Usage

colSpan property sets or returns the value of colspan attribute.

colspan attribute specifies the number of columns in a table cell can be spanned.

Tip: Use rowSpan property to set or return the value of rowspan attribute.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support colSpan property.


grammar

Back colSpan properties:

tableheaderObject .colSpan

Setting colSpan properties:

tableheaderObject .colSpan=number

Property Value

描述
number 规定一个单元格可横跨的列数。

technical details

return value: Number representing the number of columns in a table cell can be spanned.


More examples

Examples

Returns a specified number of columns in a table cell can be spanned:

var x = document.getElementById("myTh").colSpan;
document.getElementById("demo").innerHTML=x;

x The output is:

2

try it"


related articles

HTML Reference Manual: HTML <TH> colspan attribute


TableHeader Object Reference TableHeader objects