Is there a way to determine the number of divs inside a li element?
Below is the code I've tried, but it's not functioning as expected. (The issue is that every img receives the class, even when there's only 1 div inside the li.)
if($('.lookbook ul li').find('div').length > 1){
$('.lookbook ul li img').addClass('lbcursor');
}
Here is the HTML structure:
<div class="lookbook>
<ul>
<li>
<div><img/></div>
<div></div>
</li>
<li>
<div><img/></div>
<div></div>
</li>
<li>
<div></img></div>
</li>
</ul>
</div>
The third img should not receive the class.
I need to count the number of divs in the li element, and if there's more than 1 div, the class .lbcursor should be added to the img.
I found a similar answer here on Stack Overflow, but it doesn't seem to work for my situation.
Upon further inspection, I realized that the if clause is correct. The problem lies in which elements are receiving the class.