Get ID of clicked on element in function

Posted by skerit on Stack Overflow See other posts from Stack Overflow or by skerit
Published on 2010-06-01T19:41:59Z Indexed on 2010/06/01 19:43 UTC
Read the original article Hit count: 204

Filed under:
|

I want to get the ID of an element I click on. I put the function in the onclick element, like this:

<a id="myid" class="first active" onclick="markActiveLink();" href="#home">Home</a>

And this is in the function:

function markActiveLink() {   
    alert($(this).attr("id"));
}

This doesn't work, as it says it isn't defined. Does it really forget about the ID, do I have to type it in the onclick?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery