xxxxxxxxxx
$('#button').on('click', myFunction);
function myFunction() {
var that = $(this);
console.log(that);
}
xxxxxxxxxx
// use 'this'
$("button").click(function() {
$(this).css("background-color", "red")
})
xxxxxxxxxx
$(".my-element").click(function() {
// $(this) refers to the current element that was clicked
myFunction($(this));
});
function myFunction(element) {
// Do something with the element
element.css("color", "red");
}