Hello I am using create element and my question is if the function can be executed when the page is loaded something like in jquery "document ready".
I am currently using this code which works when the user clicks on the div. It works for me for other purposes but now I need the function to run when the div loads or when the page loads.
My code:
s.a.createElement("div", { id: "iframe", style: { backgroundColor: "red" },
onClick: function () {
document.getElementById("iframe").innerHTML += "<iframe src='https://site.test' frameborder='0' id='iframe' style='display: block; overflow: hidden; border: none; height: 100vh; width: 100vw;'></iframe>";
},
},
),
Poor changing onClick for OnLoad but without success.
I tried this but it gives me an error.
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed');
});
s.a.createElement("div", { id: "iframe", style: { backgroundColor: "red" },
window.addEventListener('DOMContentLoaded', (event) => {
document.getElementById("iframe").innerHTML += "<iframe src='https://site.test' frameborder='0' id='iframe' style='display: block; overflow: hidden; border: none; height: 100vh; width: 100vw;'></iframe>";
},
},
),