Results 1 to 3 of 3

Thread: Finding out which a tag was clicked?? Possible?

  1. #1
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Question Finding out which a tag was clicked?? Possible?

    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:
    HTML Code:
    <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?
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Code:
    <a href="" onClick="check(this.id)" id="dog"><img src="image.png"></a>
    Then you could use the function like so:

    Code:
    function check(id) {
     alert('The Link with the id of: '+id+' was clicked!');
    }
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    city_coder (04-10-2008)

  4. #3
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    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

    thanks alot!!
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •