SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot zealus's Avatar
    Join Date
    Jan 2004
    Location
    NY
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Determine what object has been clicked?

    Hi, all
    this might look like a strange request, but please bear with me.

    I need to determine (in JavaScript) which div has been clicked without passing an actual name/id of the object.

    Suppose I have the bunch of divs or spans, something like the following:
    Code:
    <div name="d1" onclick="Clicked();">Hello 1</div>
    
    <div name="d2" onclick="Clicked();">Hello 2</div>
    
    <div name="d3" onclick="Clicked();">Hello 3</div>
    Note that there are no parameters passed to Clicked().

    Now, that Clicked() javascript would have to determine which div was clicked. I'm sure it's doable, just for some reason can't quite figure it out.

    Why I want to do this is whole another issue, I just want to know if it's possible and how.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get event object and check its srcElement property.
    http://developer.mozilla.org/en/Java..._a_mouse_click
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Zealot zealus's Avatar
    Join Date
    Jan 2004
    Location
    NY
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alex.w747 View Post
    Get event object and check its srcElement property.
    http://developer.mozilla.org/en/Java..._a_mouse_click
    Worked like a charm, thanks!


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
  •