activeElement property
The activeElement
read-only property
of the Document interface returns the Element within the DOM that
currently has focus.
Often activeElement
will return a HTMLInputElement or
HTMLTextAreaElement object if it has the text selection at the time. If
so, you can get more detail by using the object's selectionStart
and
selectionEnd
properties.
Other times the focused element might be a select
element (menu) or
an input
element.
Typically a user can press the tab key to move the focus around the page among focusable elements, and use the space bar to activate one (that is, to press a button or toggle a radio button). Which elements are focusable varies depending on the platform and the browser's current configuration. For example, on macOS systems, elements that aren't text input elements are not typically focusable by default.
Note: Focus (which element is receiving user input events) is not the same thing as selection (the currently highlighted part of the document). You can get the current selection using
window.getSelection
.
Implementation
external Element? get activeElement;