title: Find the number of elements with a certain class within a div
body: <p>How do I count all the elements in the containing div with the class ‘selected’?</p>
  
  <p>My Jquery attempt:</p>
  
  <pre><code>$('.list').click(function(){
     check_no = $(this).closest("div").find('.selected').length;
     alert(check_no);
  )};
  </code></pre>
  
  <p>Also tried</p>
  
  <pre><code>check_no = $(this).closest("div").children('.selected').length;
  </code></pre>
  
  <p>But it always says 0.</p>
  
  <p>HTML</p>
  
  <pre><code>   &lt;div id=1&gt;
          &lt;ul&gt;
              &lt;li class="list all"&gt;ALL&lt;/li&gt;
              &lt;li class="list selected"&gt;1&lt;/li&gt;
              &lt;li class="list"&gt;2&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul&gt;
              &lt;li class="list selected"&gt;3&lt;/li&gt;
              &lt;li class="list selected"&gt;4&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul&gt;
              &lt;li class="list"&gt;5&lt;/li&gt;
              &lt;li class="list"&gt;6&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
      &lt;div id=2&gt;
          &lt;ul&gt;
              &lt;li class="list all"&gt;ALL&lt;/li&gt;
              &lt;li class="list selected"&gt;1&lt;/li&gt;
              &lt;li class="list"&gt;2&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul&gt;
              &lt;li class="list selected"&gt;3&lt;/li&gt;
              &lt;li class="list"&gt;4&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul&gt;
              &lt;li class="list"&gt;5&lt;/li&gt;
              &lt;li class="list"&gt;6&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>So if I click on a class list within div id 1, I want to find the number of li's with class selected.</p>