tags:

views:

98

answers:

2

Here is the structure of the HTML

<div class="submenu">
<ul>
<li></li>
<li></li>
</ul>
<ul>
    <li></li>
    <li></li>
    </ul>
<ul>
    <li></li>
    <li></li>
    </ul>
</div>

If there are three UL the the I want to add three-col class. two UL then two-col

+2  A: 

Using Jquery, $(".submenu > ul").size() gives you the count.

This will set the class on the div with class submenu:

var count = $(".submenu > ul").size();
if(count == 3)
{
  $(".submenu").addClass("three-col");
}
else if(count == 2)
{
  $(".submenu").addClass("two-col");
}
Håvard S
+2  A: 
$(function(){
  $(".submenu").addClass(
    ($(".submenu ul").size() == 2) ? "two-col" : "three-col"
  );
});
Scharrels