Why doesn't this script loop trough every ul.products element and count li.product element and then change it's css(background to yellow).
When I change < to > then background color changes to all elements. So far I know that the problem is with this script checking every parent elements ul.products but is able to count li.product.
$(document).ready(function() {
$('ul.products').each(function() {
if ($('li.product').length < 4) {
$("li.product").css("background-color", "yellow");
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<ul class="products">
<li class="product">Test</li>
<li class="product">Test</li>
<li class="product">Test</li>
<li class="product">Test</li>
<li class="product">Test</li>
</ul>
<ul class="products">
<li class="product">Test</li>
<li class="product">Test</li>
<li class="product">Test</li>
</ul>