title: Selecting alternate boxes in n number of elements using jquery/javascript
body: <p>I am working on a project and getting data in form of <code>json</code> objects. I am displaying data in perfectly in the boxes as depicted below (current). But I want to add class on alternative boxes for different colors as depicted below (required).</p>
  
  <p><img src="https://i.stack.imgur.com/w8WNL.jpg" alt="Boxes"></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>jQuery.each(Stories, function (index) {
      var lindex = 6 * PageID;
      var findex = lindex - 6;
  
      if (index + 1 &gt; findex &amp;&amp; index + 1 &lt;= lindex) {
  
          var stories = dvStoreies;
  
          if ((index) % 3 == 0) {
              stories.append("&lt;div class='dvStoriesFirst'  style='clear:left;float:left;margin-bottom:40px;' ID=story_" + index + "&gt;&lt;/div&gt;"); 
           } 
           else {
               stories.append("&lt;div class='dvStories' style='float:left;margin-bottom:40px;' ID=story_" + index + "&gt;&lt;/div&gt;");                                             
            }
       }
  });
  </code></pre>
  
  <p><strong>HTML Looks Like This:</strong></p>
  
  <pre><code>&lt;div class="stories"&gt;
      &lt;div class="dvStoriesFirst" id="s_box1"&gt;&lt;/div&gt;
      &lt;div class="dvStories" id="s_box2"&gt;&lt;/div&gt;
      &lt;div class="dvStories" id="s_box3"&gt;&lt;/div&gt;
      &lt;div class="dvStoriesFirst" id="s_box4"&gt;&lt;/div&gt;
      &lt;div class="dvStories" id="s_box5"&gt;&lt;/div&gt;
      &lt;div class="dvStories" id="s_box6"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Can anyone one help me how can I achieve this. Thanks</p>