Web Analytics Made Easy -
StatCounter Image preloading with for loop not working - CodingForum

Announcement

Collapse
No announcement yet.

Image preloading with for loop not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Image preloading with for loop not working

    So I've got some code that's intended to preload images for rollover. The code goes like this:

    Code:
    left_nav=document.getElementById('left_mouseovers');
    left_tags=left_nav.getElementsByTagName('p');
    var imgs=new Array();
    for(var i=0;i<left_tags.length;i++)
    {
      imgs[i]=new Image();
      imgs[i].src='splash_'+left_tags[i]+'.jpg';
    }
    I know the first two lines work because I use them later on in the script for a different purpose. My question, then, is why doesn't the loop preload the images?

  • #2
    it fails because left_tags is an array of object, not an array of string which is how you are using it. I assume you want to use the id of the paragraphs so the correct line of code would be:

    imgs[i].src='splash_'+left_tags[i].id+'.jpg';
    100% standards compliant code is 100% correct 100% of the time.

    Cd&

    Comment


    • #3
      D'oh! Thanks so much.

      Comment


      • #4
        It just takes a second set of eyes sometimes.
        100% standards compliant code is 100% correct 100% of the time.

        Cd&

        Comment

        Working...
        X