You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > col

col object

Browser support:
Specifies property defaults for a column in a table.
The col tag is used to specify column dependent properties for a table. You can use it together with the colgroup element, overriding the properties of the colgroup for the specific column.
This element must be placed within a table element.
Note that Firefox, Google Chrome, Safari and Opera have only partial support for this element.
For more information, please see the page for the table element.

Syntax:

Methods that return the object:
document.createElement ("col")
The base interface, through which you can add new functionalities to the col object, is the HTMLTableColElement interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: col

Possible members:

Properties
Methods
Events
Style properties
align
Sets or retrieves the horizontal alignment of the contents in an object.
all
Represents a collection of all elements contained by an element or the entire document.
attributes
Represents a collection of attribute nodes that belong to an element.
baseURI
10
Returns the base URL for the object.
behaviorUrns
Represents a collection of the Uniform Resource Names for all behaviors attached to an element.
bgColor
Sets or retrieves the background color of one or more specified columns in a table element.
canHaveChildren
Retrieves a Boolean value that indicates whether the element can contain child elements.
canHaveHTML
Retrieves a Boolean value that indicates whether the element can contain HTML formatted text.
ch
Sets or retrieves an alignment character. The alignment of the contents of the cells in the same column depends on this character. The first occurrence of the alignment character in each cell in a column will be on a vertical axis.
childElementCount
93.5
Returns the number of element nodes that are direct descendants of the current element.
childNodes
Represents a collection of all nodes that are direct descendants of an element.
children
3.5
Represents a collection of all element nodes that are direct descendants of an element.
chOff
Sets or retrieves the horizontal offset of the ch and char properties. The direction of the offset is the same as the direction of the text (dir property).
className
Sets or retrieves the style class or classes that belong to the element.
currentStyle
Represents the computed style settings for an element.
dir
Sets or retrieves the text direction as related to the lang property.
disabled
Sets or retrieves the state of an object for user interaction.
firstChild
Returns a reference to the first child of the current element.
firstElementChild
93.5
Returns a reference to the first child element of the current element.
hideFocus
Specifies or returns whether a dotted rectangle (focus rectangle) is drawn around an object while it has focus.
id
Sets or retrieves a unique identifier for the object.
innerHTML
Sets or retrieves the inner HTML content (the source code between the opening and closing tags) of an element.
innerText
Sets or returns the text content of an element including the text content of its descendants.
isContentEditable
Returns a Boolean value that indicates whether the contents of the object are editable by the user.
isDisabled
Returns a Boolean value that indicates whether the object is disabled.
isMultiLine
Returns a Boolean value that indicates whether the contents of an element can be multiline or not.
isTextEdit
Returns a Boolean value that indicates whether the createTextRange method can be used for the element.
lang
Specifies or returns the language of the element.
lastChild
Returns a reference to the last child of the current element.
lastElementChild
93.5
Returns a reference to the last child element of the current element.
localName
9
Returns the local part of the qualified name of the current node.
name
Sets or retrieves the name of an element.
namespaceURI
93.6
Sets or returns the namespace URI of the current node.
nextElementSibling
93.5
Returns a reference to the next child element of the current element's parent.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeValue
Sets or returns the value of the current node.
offsetHeight
Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.
offsetLeft
Returns the left position of an object relative to the left side of its offsetParent element, in pixels.
offsetParent
Returns a reference to the closest ancestor element in the DOM hierarchy from which the position of the current element is calculated.
offsetTop
Returns the top position of the object relative to the top side of its offsetParent element, in pixels.
offsetWidth
Returns the width of the visible area for an object, in pixels. The value contains the width with the padding, scrollBar, and the border, but does not include the margin.
outerHTML
Sets or retrieves the outer HTML content (the source code including the opening and closing tags) of an element.
outerText
Sets or returns the text content of an element including the text content of its descendants.
ownerDocument
Returns the document object that contains the current node.
parentElement
Returns the parent element of the object in the DOM hierarchy.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
parentTextEdit
Returns the closest ancestor element of the current element in the DOM hierarchy that can be used to create a TextRange object.
previousElementSibling
93.5
Returns a reference to the previous child element of the current element's parent.
previousSibling
Returns a reference to the previous node of the current element's parent.
readyState
Returns a string value that represents the state of the object.
runtimeStyle
Represents the overridden style settings for an element.
scopeName
Retrieves the local name of the namespace declared for the current element.
sourceIndex
Returns the position of the current object in the all collection of the document.
span
Specifies or returns the number of columns in a column group that share the settings defined in the col element.
style
Represents the inline style settings for an element or a CSS rule.
tagName
Returns the tag name of the current element.
tagUrn
Sets or retrieves the Uniform Resource Name (URN) of the namespace declared for the current element.
textContent
9
Sets or returns the text content of an element including the text content of its descendants.
uniqueID
Returns the unique identifier generated by the browser for the object.
vAlign
Specifies or returns the vertical alignment of the text within an object.
width
Specifies or returns the default width of the element.

Example HTML code 1:

This example illustrates the use of the col element:
<table border="1px">
    <col style="background-color: #a0f0a0;" />
    <col span="2" style="background-color: #a0a0f0;" />
    <tbody>
        <tr>
            <td>Apple</td>
            <td>$5</td>
            <td>$10.7</td>
        </tr>
        <tr>
            <td>Pear</td>
            <td>$10.50</td>
            <td>$8.20</td>
        </tr>
        <tr>
            <td>Peach</td>
            <td>$23.30</td>
            <td>$19.45</td>
        </tr>
    </tbody>
</table>
Did you find this example helpful? yes no

Example HTML code 2:

This example shows how to change the background color of a col element in JavaScript:
<head>
    <script type="text/javascript">
        function SwapBGColors () {
            var table = document.getElementById ("myTable");
            var cols = table.getElementsByTagName ("col");
            var store = cols[0].style.backgroundColor;
            cols[0].style.backgroundColor = cols[1].style.backgroundColor;
            cols[1].style.backgroundColor = store;
        }
    </script>
</head>
<body>
    <button onclick="SwapBGColors ()">Swap background colors</button>
    <br /><br />
    <table id="myTable" border="1px">
        <col style="background-color: #a0f0a0;" />
        <col span="2" style="background-color: #a0a0f0;" />
        <tbody>
            <tr>
                <td>Apple</td>
                <td>$5</td>
                <td>$10.7</td>
            </tr>
            <tr>
                <td>Pear</td>
                <td>$10.50</td>
                <td>$8.20</td>
            </tr>
            <tr>
                <td>Peach</td>
                <td>$23.30</td>
                <td>$19.45</td>
            </tr>
        </tbody>
    </table>
</body>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content