jkies00
09-08-2006, 08:06 PM
Hello,
I'm building a simple image viewer - clicking on the thumbnail images swap out the larger image. You can view it in action here:
http://addelement.com/portfolio/beamedceiling/
For some reason, it won't work in IE6. I think I'm overlooking something small. IE doesn't seem to respond to this code:
document.getElementById('viewerLg').setAttribute('src',newsrc)
Here's the complete script, so you don't have to dig it out:
function findimg()
{
var imgs,i;
// Loop through all images, check if they contain the class roll
imgs=document.getElementsByTagName('img');
for(i=0;i<imgs.length;i++)
{
if(/roll/.test(imgs[i].className))
{
// alert(imgs[i].src);
// add the function roll to the parent Element of the image
imgs[i].parentNode.onclick=function(){roll(this);};
}
}
}
function roll(o)
{
var i,isnode,src,ftype,newsrc,nownode;
// loop through all childNodes
for (i=0;i<o.childNodes.length;i++)
{
nownode=o.childNodes[i];
// if the node is an element and an IMG set the variable and exit the loop
if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
{
isnode=i;
break;
}
}
// check src and do the rollover
src = o.childNodes[isnode].src;
ftype = src.substring(src.lastIndexOf('.')-2, src.lastIndexOf('.'));
newsrc = 'viewerlg/viewerlg-' + ftype + '.jpg';
//alert(newsrc);
document.getElementById('viewerLg').setAttribute('src',newsrc);
}
window.onload=function() {
findimg();
}
What am I missing??
Thanks,
~jeff
I'm building a simple image viewer - clicking on the thumbnail images swap out the larger image. You can view it in action here:
http://addelement.com/portfolio/beamedceiling/
For some reason, it won't work in IE6. I think I'm overlooking something small. IE doesn't seem to respond to this code:
document.getElementById('viewerLg').setAttribute('src',newsrc)
Here's the complete script, so you don't have to dig it out:
function findimg()
{
var imgs,i;
// Loop through all images, check if they contain the class roll
imgs=document.getElementsByTagName('img');
for(i=0;i<imgs.length;i++)
{
if(/roll/.test(imgs[i].className))
{
// alert(imgs[i].src);
// add the function roll to the parent Element of the image
imgs[i].parentNode.onclick=function(){roll(this);};
}
}
}
function roll(o)
{
var i,isnode,src,ftype,newsrc,nownode;
// loop through all childNodes
for (i=0;i<o.childNodes.length;i++)
{
nownode=o.childNodes[i];
// if the node is an element and an IMG set the variable and exit the loop
if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
{
isnode=i;
break;
}
}
// check src and do the rollover
src = o.childNodes[isnode].src;
ftype = src.substring(src.lastIndexOf('.')-2, src.lastIndexOf('.'));
newsrc = 'viewerlg/viewerlg-' + ftype + '.jpg';
//alert(newsrc);
document.getElementById('viewerLg').setAttribute('src',newsrc);
}
window.onload=function() {
findimg();
}
What am I missing??
Thanks,
~jeff