ni**********@lexisnexis.com wrote:
Hello:
My html file contains the following image link:
<a href="some_url"><img src="MyImage.gif"></a>
How can I use Javascript to find out the value of some_url for the
given image name "MyImage.gif"?
I know how to get the image object with a given name (e.g.
"MyImage.gif"). But then how do I get the parent anchor link object and
find its href value?
document.images['myImage_1'].parentNode.href
file test.htm :
<html>
<script type="text/javascript"><!--
function linkOfImage(pict) {
var Href=null, Link, thisImg;
var I = document.getElementsByTagName('IMG');
for(var i=0;i<I.length;i++) {
thisImg = I[i].src.substring(I[i].src.lastIndexOf('/')+1)
if(pict==thisImg) {
Link = I[i].parentNode;
if(Link && Link.tagName.toLowerCase()=='a')
Href = Link.href;
}
}
if(Href) alert('link href = '+Href);
else alert('not found');
}
// --></script>
<p><a href="#" onclick="linkOfImage('i_2.jpg');">image href i_2.jpg</a>
<p><a href="t_1.htm"><img src="i_1.jpg"></a>
<p><a href="t_2.htm"><img src="i_2.jpg"></a>
<p><a href="t_3.htm"><img src="i_3.jpg"></a>
</html>
--
Stephane Moriaux et son [moins] vieux Mac