Reputation: 717
I am trying to detect <li>
elements which have <ul>
child.
This is what I tried, but it is not working:
$('ul.meta-menu li').each(function() {
if ( $(this).has('ul') ) {
addClass('par');
}
});
Upvotes: 1
Views: 57
Reputation: 10824
Try this:
$(function(){
$('ul.meta-menu').find('ul').addClass('par');
});
If you want to style only the parent li
see this example
Upvotes: 0
Reputation: 7328
Try:
$('ul.meta-menu li').has('ul').addClass('color');
OR
$('ul.meta-menu li ul').parent().addClass('bold');
Either would work.
Upvotes: 1
Reputation: 22619
using child selector
$('ul.meta-menu li > ul').each(
$(this).parent().addClass('par');
)
Upvotes: 1
Reputation: 15709
Try this:
$('ul.meta-menu li').each(function() {
if ($(this).find('ul').length){
$(this).addClass('par');
}
});
Upvotes: 3