Back to Content

ShadowRoot: activeElement property

files/en-us/web/api/shadowroot/activeelement/index.md

latest574 B
Original Source

{{APIRef("Shadow DOM")}}

The activeElement read-only property of the {{domxref("ShadowRoot")}} interface returns the element within the shadow tree that has focus.

Value

The {{domxref('Element')}} which currently has focus, or null if there is no focused element.

Examples

js
let customElem = document.querySelector("my-shadow-dom-element");
let shadow = customElem.shadowRoot;
let focusedElem = shadow.activeElement;

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("Document.activeElement")}}