I want to add loader on my site when I load the site then I set up the SetTimeout for 2 secs then I add the hidden class, but somehow it won't work, any ideas?
const preLoader = document.getElementById('preloader');
function loaderSite() {
preLoader.classList.add('hidden');
}
window.addEventListener('load', () => {
setTimeout(loaderSite, 2500);
}, false);
<div class="" id="preloader">
<div id="loader"></div>
</div>
<div clas="navbar"></div>