Break For inside an IF

0

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 ...

    
asked by anonymous 16.10.2017 / 03:54

1 answer

0

Both ifs has return inside, so it never reaches break . I suggest you remove the two returns so that the code will reach break normally.

    
26.02.2018 / 23:04