Count the no of LI then add class to parent UL.
        Posted  
        
            by Wazdesign
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Wazdesign
        
        
        
        Published on 2010-05-11T11:33:55Z
        Indexed on 
            2010/05/11
            11:44 UTC
        
        
        Read the original article
        Hit count: 335
        
<ul class="taglib-ratings thumbs">
<li id="qezr_yourRating">
  <a href="javascript:;" class="rating rate-up "></a>
</li>
</ul>
<ul class="taglib-ratings thumbs">
<li id="qezr_yourRating">
  <a href="javascript:;" class="rating rate-up "></a>
</li>
<li id="qezr_yourRating">
  <a href="javascript:;" class="rating rate-up "></a>
</li>
</ul>
I want to apply the class to the UL on base of the Count of the Inner LIs.
Like if it has two LI then the class should be like two-thumbs Like if it has one LI then the class should be like one-thumbs
I am trying this JS but not working it returns 2
jQuery(document).ready(function(){
var countLi = $(".taglib-ratings > li").size();
alert(countLi);
if(countLi == 2)
{
  $(this).parent('.taglib-ratings').addClass('2-col');
  alert ('this ul has 2 li');
}
else if(countLi == 1)
{
  $(this).parent('.taglib-ratings').addClass('2-col');
   alert ('this ul has 1 li');
}
else if(countLi > 2)
{
  alert ('this ul has'+ countLi +' li');
}
});
Here is the JSbin link to the same.
© Stack Overflow or respective owner