title: jQuery - Count elements with a certain class inside a parent element
body: <p>I got this HTML structure:</p>
  
  <pre><code>&lt;form&gt;
      &lt;input class="myTrigger" type="radio" value="1"/&gt;
      &lt;input class="myTrigger" type="radio" value="2"/&gt;
      &lt;fieldset&gt;
          &lt;ul class="class1"&gt;
              &lt;li&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="class2"&gt;
              &lt;li&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
          &lt;ul class="class2"&gt;
              &lt;li&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="class2"&gt;
              &lt;li&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>With jQuery, I need to go through each <code>ul</code> and hide the ones that don't have class <code>myClass</code> <em>(wich is defined by the <code>checked</code> <code>radio</code> <code>.myTrigger</code>)</em> then i need to check for the now empty <code>fieldset</code>'s <em>(ie: <code>fieldsets</code> where no ul has class <code>myClass</code>)</em> and hide them entirely.</p>
  
  <p>So far, i was able to hide the desired <code>ul</code>'s, but not the <code>fieldsets</code>. This is what i got:</p>
  
  <pre><code>function myFunction() {
  
          var myClass = "class"+($("radio:checked").attr("value"));
          var productGroup = $("form ul");
  
          $("form fieldset").each(function(index){
  
              groupCheck = 0;
  
              $.each(productGroup, function(index, obj){
                  if($(obj).hasClass(myClass))
                      {
                          groupCheck += 1;
                          $(obj).show();
                      }
                  else
                      {
                          $(obj).hide();
                      };
              })
  
              if (groupCheck == 0)
                  {
                      $(this).hide();
                  }
              else {
                      $(this).show();
                  };
  
          });
  
      };
  myFunction();
  $(".myTrigger").change(myFunction);
  </code></pre>
  
  <p>Also i got other scripts on the same page toggling the same ul's
  <code>ex:</code> <code>(legend).click(function(){$(this).siblings("ul").toggle();});</code>
  so can't hide the fieldsets based on the <code>ul</code>'s beeing hidden already. instead I need to look for the classes ("myClass") beeing present or not.</p>
  
  <p><em>(ie: while the small script toogles the ul's just for user convinience "myFunction" needs to filter the ul's and fieldsets to be shown based on "myTrigger" selection.)</em></p>