I need to pass a special selector to an event handler. The special selector is calculated by a function:
var getSelectableItems = function () {
return $('.item').not('.disabled');
}
$(document).ready(function () {
$body = $('body');
$body.on('click', $(getSelectableItems()), function () {
// .. do something
});
});
The getSelectableItems()
method is just a sample. My real code looks different. My point is: how can I have a function return a selector and use this selector in the kind of click event handler shown?
My current solution fires on every click / any DOM element. But I want the click event to fire only on clicks on DOM elements returned by a function.