i realise this is probably classed as a duplicate however I've read this question and the replies in detail but still can't get my head around it.
I have this code, but within the 'focus' function, 'i' is always 2, (the pageSearchInput.length value), and I want it to be 0,1 respectively on each loop.
I understand that this is a scoping issue but I can't work out how to fix this without simply using 'let'.
If someone could explain how this works i'd be very grateful.
for (i = 0; i < pageSearchInput.length; i++) {
pageSearchInput[i].addEventListener("focus", function(){
pageSearchContainer[i].style.outline = "4px solid #ffcc33";
pageSearchButton[i].style.backgroundColor = "#008920";
pageSearchButton[i].style.border = "1px solid #008920";
});
}