I am trying to add a class on page load using javascript. I'm currently learning javascript so bear with me. I am just trying to change the background color of an element as a test shown below. I get the error "Uncaught TypeError: Cannot read property 'classList' of null"
I know I am more than likely missing a very simple step here so would appreciate any advice.
Thanks all
window.onload = onPageLoad();
function onPageLoad() {
document.querySelector('.home').classList.add = ('active');
}
.bg-yellow {
background-color: yellow;
}
.active {
background-color: green;
}
div {
height: 400px;
width: 400px;
}
<div class="bg-yellow"></div>