title: Displaying a loading gif for 5 seconds automatically
body: <p>I want to display a loading gif automatically when the user goes to the website and then after 5 seconds it goes away.</p>
  
  <p>I found this script which does what I want, but it does not do it automatically. The user needs to click on the button to start it which kind of defeats the purpose.</p>
  
  <pre><code>&lt;input type = "button" value = "Show image for 5 seconds" onclick = "show()"&gt;&lt;br&gt;&lt;br&gt;
  &lt;div id = "myDiv" style="display:none"&gt;&lt;img id = "myImage" src = "images/ajax-loader.gif"&gt;&lt;/div&gt;&lt;br&gt;
  
  &lt;script type = "text/javascript"&gt;
  
  function show() {
      document.getElementById("myDiv").style.display="block";
      setTimeout("hide()", 5000);  // 5 seconds
  }
  
  function hide() {
      document.getElementById("myDiv").style.display="none";
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>If there is any way in which I can do this, or if there is a better way of doing it please just comment.</p>