title: How to get the number of columns when elements are floated left
body: <p>This is the reduced case:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var columns = null,
    firstPositionTop = $('div').eq(0).offset().top;
  
  $('div').each(function(index) {
  
    var thisPositionTop = $(this).offset().top;
  
    if (thisPositionTop !== firstPositionTop &amp;&amp; columns == null) {
  
      columns = index;
  
    }
  
  });
  console.log(columns);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>div {
    width: 15%;
    padding-bottom: 15%;
    margin: 5%;
    background: DeepPink;
    float: left;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;
  &lt;div&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am trying to figure out the easiest way to calculate the number of columns (4 in the above example) using JavaScript or jQuery.</p>
  
  <p>Is there a simpler way?</p>
  
  <p>(The number of elements will vary and there are media queries that will change the number of columns/rows).</p>