With this
example 1
$("#my_div").on("click", function () {
alert( $(this).attr("id") )
});
we obtain correct result, but if I use this:
example 2
function thisId () {
alert( $(this).attr("id") )
}
$("#my_div").on("click", function () {
thisId();
});
Now the result is undefined. Please tell me how I should be using this, when the selector and function using this are written as different expressions, as in example 2?
For jQuery to pass the element reference to the function you must provide the function as a reference. Try this:
Update for @bot