Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Get Element ID

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    123
    Thanks
    20
    Thanked 1 Time in 1 Post

    Get Element ID

    Hi,
    I am using jQuery and I want to get the id of the element clicked.

    So I do this:
    function get_id(id) {
    alert(id);
    }

    <a href="javascript:get_id(this.id);" id="test">Test</a>


    That returns "undefined". What is the problem?

    Thanks

  2. #2
    Regular Coder
    Join Date
    Jan 2007
    Posts
    123
    Thanks
    20
    Thanked 1 Time in 1 Post
    Sorry fixed..
    Should be:


    function get_id(sid) {
    alert(sid.id);
    }

    <a onclick="get_id(this);" id="test">Test</a>

  3. #3
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,224
    Thanks
    36
    Thanked 167 Times in 167 Posts
    so does it work now?


 

Posting Permissions

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