View Full Version : Finding out which a tag was clicked?? Possible?

04-10-2008, 02:54 PM
I was wondering if it possible to figure out using javascript, which button was pressed.

Let me explain.

Imagine a load of links on the page like so:

<a href="" onClick="check()" id="dog"><img src="image.png"></a>
<a href="" onClick="check()" id="cat"><img src="image1.png"></a>
<a href="" onClick="check()" id="horse"><img src="image2.png"></a>

etc etc..

so in the onClick function, check, i would want to be able to get the id of the a tag that was clicked.
The reason i ask is because i want to be able to build it into an ajax function. but i need to know which 1 was clicked.

Is there anyway of finding out?

04-10-2008, 03:04 PM
<a href="" onClick="check(this.id)" id="dog"><img src="image.png"></a>

Then you could use the function like so:

function check(id) {
alert('The Link with the id of: '+id+' was clicked!');

Hope this helps.

04-10-2008, 03:09 PM
Oh man that was uber quick and uber impressive. My hat comes off to you, well i dont have one on at the minute but i'll put one on later so i can take it off :P :D

thanks alot!!