I have the following code:
HTML:
<div class="sectionInner"><div class="carousel"></div></div>
<div class="sectionInner"></div>
<div class="sectionInner"></div>
<div class="sectionInner"></div>
JS:
function checkForCarousel() {
$('.sectionInner').each(function(i) {
if($(this).has('.carousel')) {
alert('We got a Carousel!');
}
else {
alert('No Carousels here')
}
});
}
checkForCarousel();
What I am trying to do is loop over the four div.sectionInner if I find a child with class of carousel then I want to append some buttons. I know I can just target the carousel directly but this is part of a bigger picture and I do have a reason for wanting to use a loop.
Anyway as the loop begins it alerts 'We got a Carousel' as you'd expect for the first div. It then carries on alerting 'We got a Carousel' when quite clearly we don't have Carousels for the other three divs. What am I doing wrong here?