Forum Moderators: open
(1) I've been happily swapping images for years with document.images.pookie.src='newimage.jpg', but now as soon as I put the image inside a DIV that no longer works -- nothing happens when I click the link that's supposed to swap the image. I tried getting the object reference of the DIV and using <theDivObj.images.pookie.src> and <window.theDivObj.images.pookie.src>, but no such luck. Is there a way to do this, or do I lose the image-swapping feature for good when I put the image inside a DIV?
(2) In other news, I'd like to use use a variable to refer to an array but JavaScript doesn't understand that. For example. I define some arrays....
window.a = new Array("...");
window.b = new Array("...");
And then I try to reference that array like so...
<A href="javascript:thefunction('a'); return false">Click me</A>
function thefunction(whichArray) {
alert(window.whichArray[3]);
}
The alert tells me "undefined".
Surely there's a way to do this, no? Thanks for your help.
function thefunction(whichArray) {
alert(eval(whichArray)[3]);
}
Sounds strange that.
theDivObj.images.pookie.src - ouch!
Give the image an id, and reference it from the document, so:
document.getElementById("_image_id_")
Roughly comparable to document.images is:
document.getElementsByTagName('img')
Now, this can be used via the div:
divObj.getElementsByTagName('img')["_image_id_"]
..but there's no point here.
At first I still couldn't get the image swap to work on my Mac, in either IE5 or Safari. I'd click the link to swap the image, and I'd still see the original image. Interestingly though, when I clicked to swap, all the other elements on the page would move out of the way, to make room for the bigger image, although it was the original image that was displayed, not the new, bigger image.
I finally tracked the problem down to the fact that I had previously swapped the DIV containing the image into an <innerHTML> block. As soon as I tried the DIV in its original location it worked fine.
So that means I have to find another way to swap my DIVs into the correct place on demand. I guess I'll change the <style="display: none¦block; position:..."> of the DIVs, but the problem there is that the DIVs are of various sizes, so I don't know how to make room for the footer of the page. This is why I wanted to use <innerHTML>, because it moves everything around properly to get out of the swapped DIV's way.
Vertically, my page is:
A (header)
B (DIVs swapped in dynamically)
C (footer)
But I guess how to get the footer to move up and down properly is a question for the CSS forum, so I'll post about this there.
Thanks again for your help. WebmasterWorld is awesome as a technical support resource. I tried to help some other people today in the forums so I'd give something back. Thanks again.