PDA

View Full Version : image access


Beck
10-18-2002, 11:57 PM
Anyone know how to access an image's src from a surrounding div tag? My setup is as follows:

<div id=whatever>
<img src=url1>
<img src=url2>
</div>

<div id=whatever1>
<img src=url3>
<img src=url4>
</div>


I have tried the following:
document.all("whatever")[0].src = newurl1;
(which didn't work, needless to say)

Trying to avoid assigning id's to the images, hoping to use some indexing scheme, such as arrays. Need to access through div tag, so the following isn't quite going to cut it:
document.images[0].src = newurl1;

Thanks in Advance

beetle
10-19-2002, 12:25 AM
var node = document.getElementById('whatever');
var img1 = (node.firstChild.nodeType==3) ? node.childNodes[1] : node.firstChild;
var img2 = (img1.nextSibling.nodeType==3) ? img1.nextSibling.nextSibling : img1.nextSibling;

change src's from there....*should* work.