Skip to content
Related Articles

Related Articles

HTML | DOM Table deleteCaption() Method
  • Last Updated : 19 Feb, 2019

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()

Below program illustrates the Table deleteCaption() method :
Example: Deleting a <caption> element.




<!DOCTYPE html>
<html>
  
<head>
    <title>Table deleteCaption() Method in HTML
  </title>
    <style>
        table,
        td {
            border: 1px solid green;
        }
          
        h1 {
            color: green;
        }
          
        h2 {
            font-family: Impact;
        }
          
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
  
    <h1>GeeksforGeeks</h1>
    <h2>Table deleteCaption() Method</h2>
  
    <p>To create a Caption for the table, 
      double-click the "Add Caption" button.</p>
  
    <p>To delete a Caption from the table, 
      double-click the "Delete Caption" button.</p>
  
    <table id="Courses" 
           align="center">
        <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 ondblclick="Add_Caption()">
      Add Caption
  </button>
  
    <button ondblclick="Delete_Caption()">
      Delete Caption
  </button>
  
    <script>
        function Add_Caption() {
            
            //  Create caption.
            var MyTable = 
             document.getElementById(
               "Courses").createCaption();
            
            MyTable.innerHTML = 
              "<strong>GeeksforGeeks</strong>";
        }
  
        function Delete_Caption() {
            
           // Delete caption.
            document.getElementById(
              "Courses").deleteCaption();
        }
    </script>
  
</body>
  
</html>

Output:

  • Before clicking the “Add Caption” button:
  • After clicking the “Add Caption” button:
  • After clicking the “Delete Caption” button:

Supported Browsers:

  • Apple Safari
  • Internet Explorer
  • Firefox
  • Google Chrome
  • Opera



My Personal Notes arrow_drop_up
Recommended Articles
Page :