I am trying to simply hide my loading div once the main div is fully loaded in JQuery, all the suggestions I have tried online don't seem to work and I am stuck.
I tried to initially do it sequentially like this:
$("#main").show();
$("#loading").hide();
But the hide function triggered before the show was complete
Then I tried to do it in the callback function as below:
$("#main").show(500, function(){
$("#loading").hide();
});
But this fired too early so the loading would disappear and there would be nothing for a half second until the main div showed which was not what I wanted.
Then I tried to use the promise method as shown below:
$("#main").show().promise().done(function(){
$("#loading").hide();
});
But this hide the loading div immediately and you could hardly see it before the main div showed.
I can not find any other way to do this.