How do I check if a list item has more than 1 direct span child element in jquery? I have something now like:
if ( $('li:has(span)') ) {
alert ('has span');
}
That will alert already when there's one span child, and also if there are nested li's who themselves have one or more span child elements.
This will alert if there is 2 or more child span elements.
$('li').each(function(){
if($('> span',this).length >= 2)
{
alert('has span');
}
});
or using A. Wolff filter answer.
$('li').filter(function(){return $('> span',this).length > 1;});
http://jsfiddle.net/6tzbJ/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With