carousel: function(){
var $carouselCr = $('#carousel'),
$tabCr = $('.carouselTabs', $carouselCr),
$itemCr = $('.carouselContents', $carouselCr),
tabAmount = (function(){
if($('a', $tabCr).length === $('.item', $itemCr).length){
return $('a', $tabCr).length;
}else{
throw "error: verschillend aantal tabs vs items";
}
})();
var i = tabAmount;
while(i--){
var item = $($('.item', $itemCr)[i]),
tab = $($('a', $tabCr)[i]);
console.log(item, tab);
$(tab).click(function(){
$('.item', $itemCr).hide();
$(item).show();
})
}
}
As you can see, i'm trying to attach a click event to each 'tab', to select each 'item'. I'm doing something wrong. All the tabs refer to the first item.
If i log $('.item', $itemCr)[i]
inside the loop it will return all the different items, not just the first.
Simplified HTML structure
<div id="carousel" class="block">
<div class="carouselTabs">
<a href="#">
</a>
<!-- repeating -->
</div>
<div class="carouselContents">
<div class="item">
</div>
<!-- repeating -->
</div>
</div>