<HTMLElement>.onFocus()

Attaches an event handler callback function to the “focus” event of an element.

Usage:
HTMLElement = Element.onFocus(callback)
Member of:
HTMLElement
Parameters:
callback – the function to call when the “focus” event occurs (required).
Returns:
The HTMLElement it was called on, thus allowing for command chaining.
Notes:
  • This is just a shorthand function for the .on method, specific for the “focus” event. See there for more information and examples.
  • The “focus” event handler can be attached to any HTMLElement, but of course only makes sense for elements which are either naturally focusable (e.g. <a>, <input>, <button>, <textarea>, etc.), or are otherwise made focusable (e.g. by setting the tabindex property).
  • Focus behaviour can differ on different platforms. Make sure to extensively test any function that relies on focussing with as many browsers on many different operating systems.

See also

More information