Reputation: 8462
I want to avoid the overhead of calling $("#)
again and wanted to reference the element that is already selected in the selector, something like using this
any help?
$("#aModel1").click(function () {
alert( ??? .attr("myattribute") );
});
Upvotes: 0
Views: 42
Reputation: 4392
jQuery $(this)
will do it
$("#aModel1").click(function () {
alert( $(this).attr("myattribute") );
}
Upvotes: 1
Reputation: 216
Inside the event handler this
is usually binded to the source element:
$("#element").click(function() {
alert($(this).attr('myattribute'));
});
Or you can save the reference to the element:
var element = $("#element");
element.click(function() {
alert(element.attr('myattribute'));
});
Upvotes: 0
Reputation:
Is there a reason you cant use
this
??
$("#aModel1").click(function () {
alert($(this).attr("myattribute") );
});
Upvotes: 1