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{  } 

http://jsfiddle.net/hvptw/9/

try code:

$('ul.level2').each(function(i){     $(this).addclass('count'+i.tostring()); }); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -