It’s a little embarrassing, are you just trying to "fall asleep"?
You can wait for the item to load using:
document.querySelector(selector).onload = function() {
}
Some working snippets, run it:
document.querySelector("body").onload = function() {
setTimeout(function () {
document.querySelector("#my_element").style.display = "block"
}, 1000);
}
#my_element{
width: 100px;
height: 100px;
background-color: red;
display: none;
}
<div id="my_element"></div>
Run codeHide resultIf you want to wait timehow you installed the function and selectorwhich should appear after that time.. You can take into account simple setTimeout()and CSS.
Follow the example below, hope this helps:
window.onload = function() {
waitForElementDisplay("#my_element", 1000);
}
function waitForElementDisplay (selector, time) {
console.log(document.querySelector(selector));
if (typeof document.querySelector(selector) !== "undifined") {
setTimeout(function () {
document.querySelector(selector).style.display = "block"
}, time);
}
}
#my_element{
width: 100px;
height: 100px;
background-color: red;
display: none;
}
<div id="my_element"></div>
Run codeHide result