admin管理员组文章数量:1023758
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?
Share Improve this question edited Feb 23, 2021 at 12:26 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 2, 2018 at 19:05 BlueboyeBlueboye 1,4944 gold badges27 silver badges54 bronze badges 3-
Hive you tried just placing
hideColor()
before the</body>
end tag? – zer00ne Commented Mar 2, 2018 at 19:07 -
1
How do you load this script? Did you put it in
<head>
, at the end of<body>
or is it loaded asynchronously? – zero298 Commented Mar 2, 2018 at 19:09 - How is the page getting generated? Is it a static file or a dynamic script? It sounds like it is a script that is not closing the connection after sending the page, thus the perpetual "loading" state. – Useless Code Commented Mar 2, 2018 at 20:13
1 Answer
Reset to default 3This 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>
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?
Share Improve this question edited Feb 23, 2021 at 12:26 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 2, 2018 at 19:05 BlueboyeBlueboye 1,4944 gold badges27 silver badges54 bronze badges 3-
Hive you tried just placing
hideColor()
before the</body>
end tag? – zer00ne Commented Mar 2, 2018 at 19:07 -
1
How do you load this script? Did you put it in
<head>
, at the end of<body>
or is it loaded asynchronously? – zero298 Commented Mar 2, 2018 at 19:09 - How is the page getting generated? Is it a static file or a dynamic script? It sounds like it is a script that is not closing the connection after sending the page, thus the perpetual "loading" state. – Useless Code Commented Mar 2, 2018 at 20:13
1 Answer
Reset to default 3This 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>
本文标签: javascriptaddEventListener() for DOMContentLoaded is not workingStack Overflow
版权声明:本文标题:javascript - addEventListener() for DOMContentLoaded is not working - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745605801a2158720.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论