How can I send the jQuery selector to a callback function? For example, the following code, on a button click, would hide the button selected by the jQuery object.
function cb (target) {
target.hide();
}
$('#button').on('click', cb);
How can I send the jQuery selector to a callback function? For example, the following code, on a button click, would hide the button selected by the jQuery object.
function cb (target) {
target.hide();
}
$('#button').on('click', cb);
The function is executed within the scope of the element that raised the event so you don't need to pass anything - just use the
thiskeyword. Eg.$(this).hide():