How to use JavaScript DOM to change the padding of a table?

JavascriptObject Oriented ProgrammingFront End Technology

To change the padding of a table, use the DOM padding property. You can try to run the following code to change the padding in JavaScript −

Example

<!DOCTYPE html>
<html>
   <head>
      <script>
         function paddingFunc(x) {
            document.getElementById(x).style.padding = "20px";
         }
      </script>
   </head>
   <body>
      <table style = "border:2px dashed 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 = "paddingFunc('newtable')" value = "Change Table Padding">
      </p>
   </body>
</html>
raja
Updated on 23-Jun-2020 10:59:21

Advertisements