I am making a multipage website. I add this preloader to my index page only. I don't get errors in index pages but get many errors on my other pages for this.
The errors i found: main.js:10 Uncaught TypeError: Cannot set property 'textContent' of null Here :
function loader(success) {
document.body.style.overflowY = 'hidden';
let time = window.onload;
let obj = document.querySelector('.preLoader'),
inner = document.querySelector('.preLoader .count');
let w = 0,
t = setInterval(function() {
w = w + 1;
inner.textContent = w + '%';
if (w > 99) {
obj.classList.add('loaded');
document.body.style.overflowY = 'auto';
clearInterval(t);
w = 0;
if (success) {
return success(t);
}
}
}, time);
}
loader();
<!-- PRELOADER -->
<div class="preLoader t_center g_center fixed" id="preLoader">
<div class="count">%</div>
</div>