Open In App

HTML DOM Table deleteCaption() Method

Last Updated : 03 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The Table deleteCaption() method is used for deleting a <caption> element and removing its content from the table. It can be only used if a <caption> element already exists.

Syntax:

tableObject.deleteCaption()

Example: In this example, delete table caption element using tableObject.deleteCaption() method.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Table deleteCaption() Method in HTML
    </title>
    <style>
        table,
        td {
            border: 1px solid green;
        }
    </style>
</head>

<body>
    <h2>Table deleteCaption() Method</h2>

    <p>
        To create a Caption for the table,
        click the "Add Caption" button.
    </p>

    <p>
        To delete a Caption from the table,
        click the "Delete Caption" button.
    </p>

    <table id="Courses">
        <tr>
            <td>Java</td>
            <td>Fork Java</td>
        </tr>
        <tr>
            <td>Python</td>
            <td>Fork Python</td>
        </tr>
        <tr>
            <td>Placements</td>
            <td>Sudo Placement</td>
        </tr>

    </table>
    <br>

    <button onclick="Add_Caption()">
        Add Caption
    </button>

    <button onclick="Delete_Caption()">
        Delete Caption
    </button>

    <script>
        function Add_Caption() {
            //  Create caption.
            let MyTable =
                document.getElementById(
                    "Courses").createCaption();

            MyTable.innerHTML =
                "<strong>GeeksforGeeks</strong>";
        }

        function Delete_Caption() {
            // Delete caption.
            document.getElementById(
                "Courses").deleteCaption();
        }
    </script>
</body>

</html>

Output:

deleteCaption
add/delete captions

Supported Browsers:

  • Apple Safari
  • Firefox
  • Google Chrome
  • Opera

Next Article
Article Tags :

Similar Reads