I am trying to retrieve the clicked object name through the code below, but I get [object object] only, how can I get the object name?
<a href="#" class="clickme">click</a>
$('.clickme').click(function(){
alert($(this));
return false;
});
I would like to get '.clickme'
as my object name.
Thanks.
EDIT:
thanks for the help guys. sorry that for not being clear.
I want to get the object name dynamically when I turn this jquery click() into a customised function or a plugin.
so,
<a href="#" class="clickme">click</a>
$('.clickme').click(function(){
alert($(this));
return false;
});
I would like to get '.clickme'
as my object name.
and,
<a href="#" id="clickme">click</a>
$('#clickme').click(function(){
alert($(this));
return false;
});
I would like to get '#clickme'
as my object name.
so you notice sometime I want to get id name but sometime I want to get the class name as the object name.
jQuery does have an internal property
selector
that can be used to find what you're looking for:However you can't access this within the
click(function(e){})
since you have to reselect usingthis
:However, when you create the click function you can assign that element to a variable and reference it within: