Computer >> Computer tutorials >  >> Programming >> Javascript

How to know whether the border and background of empty cells are hidden or not with JavaScript?


To know whether the background and border of empty cells are hidden in JavaScript, use the emptyCells property.

Example

You can try to run the following code to set whether to show the border and background of empty cells or not with JavaScript −

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, td {
            border:1px solid;
         }
      </style>
   </head>
   <body>
      <table id="myID" style="empty-cells:hide;">
         <tr>
            <td>One</td>
            <td>111</td>
         </tr>
         <tr>
            <td>Two</td>
            <td>222</td>
         </tr>
         <tr>
            <td>Three</td>
            <td></td>
         </tr>
      </table>
      <br>
      <button type="button" onclick="display()">Return</button>
      <script>
         function display() {
            document.write(document.getElementById("myID").style.emptyCells);
         }
      </script>
   </body>
</html>