Set whether the table border should be collapsed into a single border or not with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To set whether a table border is to be collapsed, use the borderCollapse property and set it to collapse. You can try to run the following code to set the table border to collapse −

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <table id="newTable" border="2">
         <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 collapse</button>
      <script>
         function display() {
            document.getElementById("newTable").style.borderCollapse = "collapse";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 10:23:22
Advertisements