When attempting to change text color on hover, an error message is displayed:
Uncaught TypeError: Cannot read property 'style' of undefined at HTMLDivElement
<a data-tab="Tab 1">
<div class="tab-link__text">Tab1</div>
</a>
<a data-tab="Tab 2">
<div class="tab-link__text">Tab2</div>
</a>
let tabLinks = document.getElementsByClassName('tab-link__text');
let tabLinksArr = Array.prototype.slice.call( tabLinks )
tabLinksArr[0].style.color = "red"; //This successfully changes the color
for (i=0; i < tabLinksArr.length; i++) {
tabLinksArr[i].addEventListener('mouseover', function(){
tabLinksArr[i].style.color = "red"; //However, this does not work
});
}
The styling works fine when outside the for loop, but encounters issues inside.