How to set the position of the table caption in JavaScript?

HTMLJavascriptProgramming Scripts

To set the position of the table caption, use the JavaScript borderWidth property. Set the position using this property.

You can try to run the following code to learn how to set the position of the caption of a table −

Example

Live Demo
<!DOCTYPE html>
<html>
   <body>
      <table id = "newTable" border = "2">
         <caption id = "newCaption">Employee Details</caption>
         <tr>
            <th>EmpID</th>
            <th>EmpName</th>
            <th>EmpDept</th>
         </tr>
         
         <tr>
            <td>001</td>
            <td>Amit</td>
            <td>IT</td>
         </tr>
         
         <tr>
            <td>002</td>
            <td>John</td>
            <td>Finance</td>
         </tr>
         
         <tr>
            <td>003</td>
            <td>David</td>
            <td>Marketing</td>
         </tr>
      </table>
      <br>
      
      <button onclick = "display()">Click to change caption position</button>
      
      <script>
         function display() {
            document.getElementById("newCaption").style.captionSide = "bottom";
         }
      </script>
      
   </body>
</html>
raja
Published on 26-Feb-2018 11:20:46
Advertisements