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

How to return or set the width of the columns with JavaScript?


Use the JavaScript columnWidth property to set the width of the columns.

Example

You can try to run the following code to set the width of the columns with JavaScript:

<!DOCTYPE html>
<html>
   <body>
      <p>Set the width of the columns</p>
      <button onclick="display()">Change Width</button>
      <div id="myID">
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
         This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
      </div>
      <script>
         function display() {
            document.getElementById("myID").style.columnWidth = "70px";
         }
      </script>
   </body>
</html>