I have two main div tags within my code: one is the main display (id = 'test') and the other is a loading screen (id = 'loading') that covers the whole screen while the main display is being fetched. The main display's div code is all being done through a javascript function. So far, here's what I have:
<body>
<div class="container" id="test"></div>
<div class="loader-wrapper" id="loading">
<span class="loader"><span class="loader-inner"></span></span>
</div>
<script>
$(window).on('load', function(){
$('#loading').fadeOut();
});
</script>
</body>
For reference, "test" is handled by a js class I've created that fetches data from a localhost, which contains certain data to be displayed. The data is returned in the form of a dictionary. Based on the length of this dictionary, my code loops that many times and creates the innerHTML of test in a user-friendly format. If the data is empty, an else-statement is in place to display a different innerHTML for test. The code from the js function is as follows:
const renderTest = async function(){
var row_string = "";
var response = await fetch(`http://localhost:3000/getData`);
const data = await response.json();
//create the innerHTML of test
}
renderTest();
The issue I am having trouble solving is that the jquery function I made finishes before the "test" div is done being loaded. I tried substituting window with "#test" but found that the loading screen is always present with that. What's the best way to solve this? I would love to have a way where I can simply fadeOut the loading screen once renderTest is complete.