Home >Web Front-end >HTML Tutorial >How to create table header using JavaScript DOM?

How to create table header using JavaScript DOM?

王林
王林forward
2023-09-11 21:49:111403browse

如何使用JavaScript DOM创建表格标题?

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

Example

You can try running the following command code to learn how to create a table title -

Live Demonstration

<!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(&#39;newtable&#39;)" value="Display Table Caption">
      </p>
   </body>
</html>

The above is the detailed content of How to create table header using JavaScript DOM?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete