I am trying to change the background color for my div's with the class "box" with javascript on page load. I am changing the document with getElementsByClassName, but when I load the page nothing happens. I've checked for typos and researched the internet, but really cannot figure this one out...and it's so simple too.
Please help
window.onload = function changeDivColor () {
document.getElementsByClassName("box").style.backgroundColor = "blue";
};
.box {
background-color: red;
display: flex;
align-items: center;
justify-content: center;
vertical-align: middle;
margin: 5px;
border-radius: 5%;
}
<html>
<link rel="stylesheet"
type="text/css"
href="/Users/skyler/Documents/GitHub/Code/style.css"/>
<script src="javascript.js"> </script>
<div class="container">
<div class="box"> <label> <input type="checkbox"> <div class="label-text"></div> </label> </div>
</div>
</html>