Frazer Findlater Frazer Findlater - 2 months ago 7
CSS Question

Do something if there are 8 children, if not do nothing

I currently have markup that looks like this -

<div class="carousel">
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
<div class="carousel-cell"></div>
</div>


And I'm trying to trigger a carousel plugin when there are more than 8 children called "carousel-cell" present and if there isn't then do nothing. Does somebody have a jquery call for this?

Answer

You can check the length of jQuery object as shown below:

if($('.carousel .carousel-cell').length >= 8) {
    $('.carousel').yourPlugin();
}