I tried to create a for loop which loops through all buttons in an array I made – and it’s supposed to work according to: (https://www.w3schools.com/js/js_loop_for.asp)
But it does not.
I have no idea what should I do, since I haven’t found anything about that on the web.
Thank you for your time.
Here is the code
const buttons = document.getElementsByClassName('zoom-btn');
for (i = 0; i < buttons.length; i++) {
buttons[i].onmouseover = () => {
buttons[i].style.backgroundColor = "red";
}
};
#article-navbar {
display: flex;
flex-wrap: wrap;
align-items: center;
align-content: center;
position: fixed;
width: clamp(286px, 504px, 506px);
height: clamp(90px, 182px, 184px);
top: 36vw;
left: 4vw;
background-color: cyan;
}
.zoom-btn {
background-color: slategray;
color: white;
padding: 18px 10px;
margin-top: 12px;
margin-left: 10px;
font-size: 16px;
position: relative;
}
.reset-btn {
background-color: blue;
}
.zoom-hover {
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="a.css">
</head>
<body>
<div id="article-navbar">
<a id="button-RE" ; class="zoom-btn reset-btn">Reset</a>
<a id="button-A1" ; class="zoom-btn">Block 1</a>
<a id="button-A2" ; class="zoom-btn btn-deactivated">Block 2</a>
<a id="button-A3" ; class="zoom-btn btn-deactivated">Block 3</a>
<a id="button-B1" ; class="zoom-btn btn-deactivated">Block 4</a>
<a id="button-B2" ; class="zoom-btn btn-deactivated">Block 5</a>
</div>
<script src="a.js"></script>
</body>
</html>