I'm breaking my head for an hour and I can not understand why this BREAK is not working inside my IF:
var nextSlide = searchElement("#next-slide").addEventListener("click", function(){
var tabs = searchAllElements(".tab-name");
breakme: for(var i = 0; i < tabs.length; i++){
var currentTab = tabs[i];
if(currentTab.classList.contains("active")){
if(i == tabs.length -1){
var nextTab = tabs[0];
return nextTab.firstChild.click();
}else{
var nextTab = tabs[i + 1];
return nextTab.firstChild.click();
}
break breakme;
}
}
});
This function that I created, looks for an element with class active
and executes onclick
of next. The result is bizarre !! it continues running the for and executing other elements ...