I'm currently working on a project involving tabs that display content for two different data-targets (which is not an issue). I've implemented a script that automatically switches tabs every 5 seconds. The tab changes successfully, but the tab-content doesn't appear as expected. I'm unsure why this is happening and would greatly appreciate any assistance. Thank you.
$(document).ready(function () {
var timeInterval, currnetIndex = 1;
tabCount = 5;
var tabContentObj = $('.tab-content');
changeTabIndex();
timeInterval = setInterval(function () { changeTabIndex(); }, 4 * 1000);
function changeTabIndex() {
if (currnetIndex > tabCount) {
currnetIndex = 1;
}
tabContentObj.hide();
$('ul#myTab').find('li.active').removeClass('active');
var currentAncorObj = $('ul#myTab').find('li a').eq(currnetIndex - 1);
currentAncorObj.parent().addClass('active');
$(currentAncorObj.attr('href')).show();
currnetIndex++;
};
$('#myTab li').mouseenter(function () {
clearInterval(timeInterval);
}).mouseleave(function () {
timeInterval = setInterval(function () { changeTabIndex(); }, 4 * 1000);
});
$('#myTab li a').click(function () {
tabContentObj.hide();
$('ul#myTab').find('li.active').removeClass('active');
var currentAncorObj = $(this);
currnetIndex = $('ul#myTab').find('li a').index($(this)) + 1;
currentAncorObj.parent().addClass('active');
$(currentAncorObj.attr('href')).show();
currnetIndex++;
//return false;
});
});
... (remaining code snipped out for brevity)
Please access the Codepen demo to see the issue firsthand. Check it out here