When selecting an ID or ClassName in Javascript it does not work. The class or ID does exist and is spelled correctly. Why does Javascript tell me that Undefined is not an object(evaluating 'header.style.height = ""') while the object is defined properly? The script below is just a plain example, but I can't select (almost) anything. No matter what ID or class I select. I know that it says it can't find the object, but why?
var header = document.getElementById("header");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 128 || document.documentElement.scrollTop > 128) {
header.style.height = "48px";
} else {
header.style.height = "";
}
}