Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/6/2006 12:12 PM: Regena wrote: the image name id of the anchor.
I presume you mean "the name of the `img' element the `a' element is
parent of".
I read it as the ID of the a element that is wrapped around the image.
Fair enough, the blurred wording of the OP definitely allows for that :)
how do I do that where should I add the onClick action in the anchor or
in the image tag?
If this was a sentence, given the presumptions above, the answer would be
<a href="http://www.google.com" id="check"
onclick="alert(this.firstChild.name);"
onclick=alert(this.id);return false;
The attribute value must be quoted here, and "return false;" is neither
necessary nor viable in its current form (since it would disable the link
feature of the element).
Another solution for the latter:
<a href="http://www.google.com/" id="check"><img
name="img1" src='/images/abc.gif' border='0' alt="abc"
onclick="window.alert(this.parentNode.id);"></a>
And for the former:
<a href="http://www.google.com/" id="check"><img
name="img1" src='/images/abc.gif' border='0' alt="abc"
onclick="window.alert(this.name);"></a>
Both are not as downwards compatible as using the `onclick' attribute of the
`a' element instead, though.
PointedEars