Please could someone help me with this set of code
How can I set an event.listener to initiate code when the page has finished loading. At the moment I have used a setTimeOut but on slow connections the time out for the loader to disappear is too soon, I would like to do it without having to increase the interval time, to initiate the code only once the page and its content has finished loading. I would greatly appreciate your help. please see my code below
$('body').append('<div id="loadingDiv"><div class="loader"><img src="./images/loader/image.gif" alt="loadingImage"></div></div>');
let clearLoader = () => {
$("#loadingDiv").fadeOut(500, function () {
$("#loadingDiv").remove();
});
}
setTimeout(clearLoader, 2000);