You are here: Reference > JavaScript > client-side > HTML DOM > properties > cols (table)

cols property (table)

Browser support:
Specifies or returns the number of columns in a table.
This property is only useful to speed up the browser's rendering mechanism.

Syntax:

object.cols;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: cols

Possible values:

Integer that sets or retrieves the number of columns.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the cols attribute:
<table border="3px" cols="3" id="myTable">
    <tr>
        <td>Apple</td>
        <td>Pear</td>
        <td>Peach</td>
    </tr>
</table>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the cols property:
<head>
    <script type="text/javascript">
        function GetCols () {
            var table = document.getElementById ("myTable");
            alert (table.cols);
        }
    </script>
</head>
<body>
    <table border="3px" cols="3" id="myTable">
        <tr>
            <td>Apple</td>
            <td>Pear</td>
            <td>Peach</td>
        </tr>
    </table>

    <button onclick="GetCols ();">Get the number of columns!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content