Count the no of LI then add class to parent UL.
- by Wazdesign
<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.
http://jsbin.com/ofeda/edit