The activeElement read-only property of the ShadowRoot interface returns the element within the shadow tree that has focus.
The Element which currently has focus, or null if there is no focused element.
let customElem = document.querySelector("my-shadow-dom-element");
let shadow = customElem.shadowRoot;
let focusedElem = shadow.activeElement;
| Specification |
|---|
| HTML> # dom-documentorshadowroot-activeelement-dev> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
activeElement |
53 | 79 | 63 | 40 | 10 | 53 | 63 | 41 | 10 | 6.0 | 53 | 10 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/activeElement