[Javascript] Q on 'new Image ()'

Walter Torres walter at torres.ws
Thu Oct 18 17:29:20 CDT 2001


For example...

 var objImgBtn        = new Array ( 2 );           // make an array
     objImgBtn.up     = new Image ( 24, 12 );      // .up is an IMAGE Object
     objImgBtn.up.src = "./images/button-up.gif";  // source to an image
     objImgBtn.dn     = new Image ( 24, 12 );      // .dn is an IMAGE Object
     objImgBtn.dn.src = "./images/button-dn.gif";  // source to an image

<img src='' width='24' height='12' id='myBtn'>

<div id='myBtn2'></div>

Now I have 2 images in local cache, an image on a page and a DIV.

   document.all.myBtn.src = objImgBtn.dn.src;

Now the down button image from the array Object is in the <IMG> object.

   document.all.myBtn2.style.backgroundImage     = objImgBtn.dn.src;
   document.all.myBtn2.style.backgroundImage.src = objImgBtn.dn.src;

Neither line works!

   document.all.myBtn2.style.backgroundImage = "./images/button-dn.gif";

This does work, but it doesn't take advantage of the cached images.

Anybody have any ideas on how to have the DIV (or SPAN, for that matter)
take advantage the cached images in the 'objImgBtn' Object?

Thanks

Walter




More information about the Javascript mailing list