Steps to show loading image using javascript:
1) Create simple div tag with some Id. Example: “loading”
2) Change the content of div using innerHTML
Example:
<div id="loading"></div>
document.getElementById('loading').innerHTML = '<img src="{imagepath}" alt="Loading">';
Before loading the content to div, If we use the above code will show the loading image.
After that load your content to same div using innerHTML.