Im trying to add a classname to the nav bar when the user scroll down. I did this:
var myNav = document.getElementById("nav");
window.onscroll = function() {
"use strict";
if (document.body.scrollTop >= 150 || document.documentElement.scrollTop >= 150) {
myNav.classList.add("scroll");
} else {
myNav.classList.remove("scroll");
}
};
But it gave me an error:
Cannot read properties of null (reading 'classList')
I don't know why :(