Addclass to every "ul" and count the "ul" element -
i´ve got 3 lvl navigation , want every "ul" class "levle2" additional class called "count" counter counts "ul´s" , puts number behind class.
this how should like
<ul class="level1" > <li> <a href="#">more options</a> <ul class="level2 count1"> <li><a href="#">second level link</a></li> <li><a href="#">second level link</a></li> </ul> </li> <li> <a href="#">more options2</a> <ul class="level2 count2"> <li><a href="#">second level link2</a></li> <li><a href="#">second level link2</a></li> </ul> </li> <li> <a href="#">more options3</a> <ul class="level2 count3"> <li><a href="#">second level link3</a></li> <li><a href="#">second level link3</a></li> </ul> </li> </ul>
js code
if($('ul.level1 li').find('ul').children('ul.level3').length > 0) { var item = $('ul.level1 li').find('ul').children('ul.level3'); item.parent().addclass('count'); } else{ }
try code:
$('ul.level2').each(function(i){ $(this).addclass('count'+i.tostring()); });
Comments
Post a Comment