title: Preload images image.onload script MVC
body: <p>My application is a MVC, using MS SQL to get the image file names.  I am using the following script to preload images; would like to know How I can display hourglass cursor while waiting to complete the preload.</p>
  
  <pre><code>  function preload_images() {
              var i, count = 0;
              $('#selector').css('cursor', 'wait');
              for (i = 1; i &lt; sl; i++) {
                  images[i] = new Image();
  
                  images[i].onload = images[i].onerror = function () {
                      count++;
                      if (count == sl) {
                          $('#selector').css('cursor', 'default');
                      }
                  }
                   images[i].src = impath.toString() + im.toString() + i + ".jpg";
  
              }
          }
  </code></pre>
  
  <p>It works great first time, however, when I change the file name from a dropdownlist, the hourglass does not stop even all images are load. Thanks in advance.</p>