This should be basic, but for some reason it doesn't work for me. I just want to save the identifier when a link that has a specific class is clicked in a variable, for example:
<a href="#" id="this_id_here" class="only_this_class">Some link</a>
I would like jquery to get the link id above and store it in a variable. I tried $ this.attr ("id") and $ this.id but did not work.
This is what I have for jquery:
$(".only_this_class").click(function() { var clickedId= $(this).attr("id"); alert(clickedId); });
I just get "undefined" every time.
source share