I am new to Javascript and I am trying to add a class to an element when the page loads. Specifically, I want to change the background color of the element as a test. However, I keep running into the error message "Uncaught TypeError: Cannot read property 'classList' of null."
I know that I must be missing something simple here. Any advice would be greatly appreciated.
Thank you in advance
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>