You are here: Reference > JavaScript > client-side > HTML DOM > methods > createCaption (table)

createCaption method (table)

Browser support:
Creates an empty caption element and adds it to the current table.
If captions already exists on the current table, the createCaption method returns the first of them and does not create a new one. Note: a table element may have more than one caption in Internet Explorer and Opera, and at most one caption in Firefox, Google Chrome and Safari.
To remove the first caption from a table, use the deleteCaption method.
Note: another way to create a caption is to use the createElement method.

Syntax:

object.createCaption ( );
You can find the related objects in the Supported by objects section below.

Return value:

Returns the newly created or an existing caption element.

Example HTML code 1:

This example illustrates the use of the createCaption method:
<head>
    <script type="text/javascript">
        function CreateCaption () {
            var table = document.getElementById ("myTable");
            var myCaption = table.createCaption ();
            myCaption.innerHTML = "<b>Caption for the table.</b>";
        }
    </script>
</head>
<body>
    <table id="myTable" border="1px">
        <tbody>
            <tr>
                <td>This text is inside the table.</td>
            </tr>
        </tbody>
    </table>
    <br /><br />
    <button onclick="CreateCaption ();">Create caption for the table!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content