Reputation: 1
<a href="javascript:getClassName();" class="link">Click here</a>
I know it is possible to get the class name with the code below:
$('a').click(function() {
alert($(this).attr('class'));
})
I want to be able to use $(this)
inside a function called getClassName()
with the help of event.target
. But, this doesn't seem to work. I always get an error:
target is undefined
The function that I'm using is:
function getClassName(event) {
el = $(event.target);
alert(el.attr('class'));
}
And I don't want to use the event.target
binding on $(body)
.
Upvotes: 0
Views: 112
Reputation: 32107
<a href="javascript:getClassName(this);" class="link">Click here</a>
Upvotes: 2