Table of Contents

About

focusin is a focus event where you can register a listener that is enable for all children elements.

Ref

Example

Track when the active element has changed

If a focus event occurs in the window or one of its children, we just print the new active element

/**
 * doc is the document
 */ 
function getElementSelector(active) {
    return active.getAttribute('id') ? `#${active.id}` : `${active.localName}.${active.className.replace(/\s/g, '.')}`;
}
parent.window.addEventListener('focusin', e => {
     console.log("The active element has changed to "+getElementSelector(e.target));
});
Just hit the tab key to change the focus and print its selector
  • Result: