By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 IT Pros & Developers. It's quick & easy.

getElementBy...

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.