I am calling a function test()
on an anchor tag like this:-
<a class="link" onclick="test();">Hello</a>
And I am trying to access the class of the anchor inside the function test():-
function test()
{
alert($(this).attr("class"));
}
But this alerts undefined
. I know that calling onclick=test(this);
instead and having the following function works:-
function test(obj)
{
alert($(obj).attr("class"));
}
But, I wanted to access the properties of the element (on which the function is called) without passing a this
. Just be able to get
/set
properties of the element (on which the function is called). Is it possible? How to do this?
Thanks,
Sandeepan