I have this code:
document.addEventListener('DOMContentLoaded', function() {
hideColor();
}, false);
But, it doesn't seem to be binding the event listener to DOMContentLoaded. I have checked document.readyState
and it says "loading". So, it means that DOMContentLoaded hasn't fired yet.
This is driving me crazy. Any ideas why it would not bind it?
I have this code:
document.addEventListener('DOMContentLoaded', function() {
hideColor();
}, false);
But, it doesn't seem to be binding the event listener to DOMContentLoaded. I have checked document.readyState
and it says "loading". So, it means that DOMContentLoaded hasn't fired yet.
This is driving me crazy. Any ideas why it would not bind it?
hideColor()
before the </body>
end tag?
– zer00ne
Commented
Mar 2, 2018 at 19:07
<head>
, at the end of <body>
or is it loaded asynchronously?
– zero298
Commented
Mar 2, 2018 at 19:09
This seems to works just fine...
function hideColor() {
console.log("DOM fully loaded and parsed");
console.log(document.readyState);
var e = document.getElementById("test");
e.style.background = "transparent";
}
document.addEventListener("DOMContentLoaded", hideColor);
#test {
background:red;
}
<div id="test">Test</div>