The Poet The Poet - 7 months ago 8
Javascript Question

How to access the current element in a selector?

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") );
});

Answer

jQuery $(this) will do it

$("#aModel1").click(function () {
    alert( $(this).attr("myattribute")  );
}