title: How to select all visible elements from list?
body: <p>I'm trying to get all visible elements from list, but I can't find the way.</p>
  
  <p>I have list</p>
  
  <pre><code>&lt;ul id="posts"&gt;
       &lt;li style="display:none"&gt;1&lt;/li&gt;
       &lt;li style="display:none"&gt;2&lt;/li&gt;
       &lt;li&gt;3&lt;/li&gt;
       &lt;li style="display:none"&gt;4&lt;/li&gt;
       &lt;li&gt;5&lt;/li&gt;
       &lt;li style="display:none"&gt;6&lt;/li&gt;
       &lt;li&gt;7&lt;/li&gt;
       &lt;li&gt;8&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>and I want to get every second visible element and add class "visible" to it.</p>
  
  <p>I want this result</p>
  
  <pre><code>&lt;ul id="posts"&gt;
       &lt;li style="display:none"&gt;1&lt;/li&gt;
       &lt;li style="display:none"&gt;2&lt;/li&gt;
       &lt;li&gt;3&lt;/li&gt;
       &lt;li style="display:none"&gt;4&lt;/li&gt;
       &lt;li class="visible"&gt;5&lt;/li&gt;
       &lt;li style="display:none"&gt;6&lt;/li&gt;
       &lt;li&gt;7&lt;/li&gt;
       &lt;li class="visible"&gt;8&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I tried something like this</p>
  
  <pre><code>var jQuerylistItems = jQuery('#posts').children('li');
  jQuerylistItems.filter(':visible').addClass('visible');
  </code></pre>
  
  <p>and it works, but not right, somethimes add class, sometimes not, I'm not sure why. </p>
  
  <p>Can somebody help me please?
  Thanks</p>