0
I’m breaking my head an hour and I can’t 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 I created, looks for an element with the class active and executes the onclick of the next. The result is bizarre!! it keeps running the for and running other elements...
The
breakis inside aifthat hasreturninifandelse, soon thebreaknor is it ever executed. What does the code want to do? and why does it invoke the click of the other tabs ? The click of the other tabs is the same as this click function ? If yes, you can incur a kind of infinite loop– Isac
there are tabs, which when clicked, perform a function that displays the content. This function I posted, it’s like a Carousel that when clicked, runs the onclick from the next tab.
– Caio Oliveira