How to create a table caption with JavaScript DOM?

HTMLJavascriptProgramming Scripts

To create a table caption, use the DOM createCaption() method.

Example

You can try to run the following code to learn how to create table caption −

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <script>
         function captionFunc(x) {
            document.getElementById(x).createCaption().innerHTML = "Demo Caption";
         }
      </script>
   </head>
   <body>
      <table style="border:2px solid black" id="newtable">
         <tr>
            <td>One</td>
            <td>Two</td>
         </tr>
         <tr>
            <td>Three</td>
            <td>Four</td>
         </tr>
         <tr>
            <td>Five</td>
            <td>Six</td>
         </tr>
      </table>
      <p>
         <input type="button" onclick="captionFunc('newtable')" value="Display Table Caption">
      </p>
   </body>
</html>
raja
Published on 26-Feb-2018 06:14:10
Advertisements