Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>UPDATE: i don't think this is possible with nth-child or another selector of jQuery. so consider using a more verbose solution:</p> <pre><code>var count = 0; $('.select-all-these').each(function() { if(!$(this).hasClass('except-these')) { count++; } if(count === 3) { $(this).text('every 3rd element'); count = 0 } });​ </code></pre> <p><a href="http://jsfiddle.net/TJdFS/2/" rel="nofollow">http://jsfiddle.net/TJdFS/2/</a> (alternative version: <a href="http://jsfiddle.net/TJdFS/" rel="nofollow">http://jsfiddle.net/TJdFS/</a>)</p> <p>:nth-child counts all matching elements ignoring any additional filters like :not.</p> <p>see jquery doc:</p> <blockquote> <p>The :nth-child(n) pseudo-class is easily confused with :eq(n), even though the two can result in dramatically different matched elements. With :nth-child(n), all children are counted, regardless of what they are, and the specified element is selected only if it matches the selector attached to the pseudo-class. With :eq(n) only the selector attached to the pseudo-class is counted, not limited to children of any other element, and the (n+1)th one (n is 0-based) is selected.</p> </blockquote> <p>Example:</p> <pre><code>&lt;div class="select-all-these"&gt;1&lt;/div&gt; &lt;div class="select-all-these except-these"&gt;2&lt;/div&gt; &lt;div class="select-all-these except-these"&gt;3&lt;/div&gt; &lt;div class="select-all-these"&gt;4&lt;/div&gt; &lt;div class="select-all-these except-these"&gt;5&lt;/div&gt; &lt;div class="select-all-these"&gt;6&lt;/div&gt; </code></pre> <p>JS:</p> <pre><code>$('.select-all-these:not(.except-these):nth-child(6)').text('nth-child counts all elements (1 based!)'); $('.select-all-these:not(.except-these):eq(1)').text('eq counts only matching elements (0 based!)'); </code></pre> <p>Result:</p> <pre><code>1 2 3 eq counts only matching elements. (0 based!) 5 nth-child counts all elements (1 based!) </code></pre> <p><a href="http://jsfiddle.net/nFtkE/2/" rel="nofollow">http://jsfiddle.net/nFtkE/2/</a> ​</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload