How to set or return the number of columns an element should be divided into with JavaScript?


To divide a div into three columns, use the columnCount property. Set the column count and divide the div.

Example

You can try to run the following code to return the numbers of columns an element is to be divided into with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p>Click below to create 4 columns</p>
      <button onclick="display()">Columns</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.
         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.columnCount = "4";
         }
      </script>
   </body>
</html>

Arushi
Arushi

e

Updated on: 23-Jun-2020

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements