It's pretty simple, really.
Code:
var slidePic=new Array(3);
slidePic[0]=slideElement1;
slidePic[1]=slideElement2;
slidePic[2]=slideElement3;
So the question is: WHAT did you just store in those array elements???
Depending on the browser, you might have stored nothing. But with most modern browsers, you will be storing *references* to *objects*. That is, references to your
<div id="slideElement1">
and friends.
But now THIS code:
Code:
function showPic(x)
{
var slideImage=document.getElementById(slidePic[x]);
slideImage.style.visibility="visible";
}
is saying that you stored the *ID* values of those objects in the array, isn't it???
After all, you are asking to getElementById( ), and so that MUST mean that you are expecting the
slidePic[x]
is an ID.
But it clearly can't possibly be an ID.
So you *COULD* do
Code:
function showPic(x)
{
var slideImage=document.getElementById(slidePic[x].id);
slideImage.style.visibility="visible";
}
But that's pretty silly. Instead, just do:
Code:
function showPic(x)
{
var slideImage = slidePic[x];
slideImage.style.visibility="visible";
}
or, even simpler,
Code:
function showPic(x)
{
slidePic[x].style.visibility="visible";
}
Which means there really isn't much point in bothering with the showPix() function, if you don't want to.
NOW...
If you want *MAXIMAL* browser compatibility *and* efficiency, then instead of initializing the array the way you are now, use this code:
Code:
var slidePic = new Array(
document.getElementById("slideElement1"),
document.getElementById("slideElement2"),
document.getElementById("slideElement3")
);
But if you want the simplest possible code--and if you can RELY upon your own naming convention for those DIVs--then *GET RID* of the silly array and just do:
Code:
function showPic(x)
{
var slideImage=document.getElementById("slideElement" + x);
slideImage.style.visibility="visible";
}