Reputation: 1911
I have a list that at times has more than one child. I'd like to style the parent if contains a number of children. I've tried a few options without success. Any help would be appreciated.
<ol class="parent">
<li>
<ol>
<li>Something</li>
</ol>
</li>
</ol>
Upvotes: 0
Views: 77
Reputation: 141877
if($element.children('ol').length >= 2){
$element has at least two 'ol's as children
}
Upvotes: 0
Reputation: 342685
Assuming you want to style the direct parent element, you can do this:
var $matches = $("ol > li > ol > li");
if($matches.length > 1) {
$matches.parent().addClass("foo");
}
Upvotes: 1