How to add a class to an element if there are less than two or three on the page.
For example there is:
<div class="block"></div> <div class="block"></div> <div class="block"></div> All have a width:
width: 33.333% There are pages on which only two or one block is displayed, it turns out that it does not look very nice. Is there a solution on jQuery that allows you to specify a condition that if there are less than 3 elements, then an additional class is added, containing for example:
width: 50%; Or if there is only one .products element, it is assigned a class containing:
width: 50%; margin: 0 auto; Described the styles for clarity of the problem.