I am currently using Brackets to work on a website and I wanted to add a loading page to it. However, I have encountered an issue with the following error message: "Uncaught TypeError: Cannot set property 'display' of undefined". The loading spinner also doesn't disappear as expected.
Below is the code snippet that I am working with:
HTML
!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link href="https://fonts.googleapis.com/css2?family=Assistant&display=swap" rel="stylesheet">
</head>
<body>
<div class="loader" id="loader"></div>
<script>
var loader = document.getElementById('loader').style.display='block';
window.addEventListener ("load", function() {
//Hide the spinner after 2 seconds
setTimeout(function(){loader.style.display = 'none';}, 2000);
});</script>
<div class="content">
Website content,,,, </div>
CSS:
.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('https://lkp.dispendik.surabaya.go.id/assets/loading.gif') 50% 50% no-repeat rgb(249,249,249);
}
`