Say we have a form with a lot of elements.
I'd like a way through generic code, to be able to add listeners to these elements so that for example, all the elements with a built-in focus event, like text inputs or dropdowns, will have this onFocus listener. In rough pseudo-code, something like this:
for each element in document
if hasBuiltInFocusEvent(element)
element.addListener(element, 'focus', indicateOnFocus);
function indicateOnFocus(element)
{
log(currentTime(), element.id, 'focus');
}
Ideally, without having to modify the existing class definitions of the elements. I can just have the code called once before the form is displayed to set up the listeners.
Please excuse my general lack of knowledge. I'm interested in whether this is feasible, in particular avoiding having to hardcode a listener for every element, because a common generic method has numerous advantages.