The Poet The Poet - 1 year ago 55
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

any help?

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

Answer Source

jQuery $(this) will do it

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