469,327 Members | 1,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

getElementBy...

I have the following code:

<a href="//www.google.com" id="check"><img name="img1"
src='/images/abc.gif' border='0'></a>

onClick action I want to print the image name id of the anchor.
how do I do that where should I add the onClick action in the anchor or
in the image tag?

Feb 6 '06 #1
5 18667
Regena wrote:
I have the following code:

<a href="//www.google.com" id="check"><img name="img1"
src='/images/abc.gif' border='0'></a>

onClick action I want to print the image name id of the anchor.
how do I do that where should I add the onClick action in the anchor or
in the image tag?

What do you mean by "print"? And do you realise that once you click
the link, another document is loaded into your browser window?
Mick
Feb 6 '06 #2
Regena wrote:
<a href="//www.google.com" id="check"><img name="img1"
I presume you mean "http://www.google.com/". The scheme part must not be
omitted if the target domain is a different one, see RFC3986. Therefore,
the above is equivalent to the resource "www.google.com" right below the
DocumentRoot, not to the www.google.com Web site.
src='/images/abc.gif' border='0'></a>
The `alt' attribute is required for the `img' element.
onClick action I want to print
I presume you mean "to display".
the image name id of the anchor.
I presume you mean "the name of the `img' element the `a' element is parent
of".
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);"<img name="img1" src='/images/abc.gif' border='0' alt="abc"></a>

PointedEars
Feb 6 '06 #3
Thomas 'PointedEars' Lahn said the following on 2/6/2006 12:12 PM:
Regena wrote:


<snip>
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.
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;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 6 '06 #4
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
Feb 6 '06 #5
sorry! I'm using frames so on click thebottom frame will change and the
image should chnage in the top frame

Feb 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by oeyvind toft | last post: by
34 posts views Thread by Steve Horrillo | last post: by
4 posts views Thread by Ryan Ternier | last post: by
11 posts views Thread by chrisdude911 | last post: by
7 posts views Thread by decren | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.