I'm trying to remove all jQuery from my code. Until now I used
if ($(selector).find(':focus').length === 0) {
// focus is outside of my element
} else {
// focus is inside my element
}
to distinguish wether the focus is inside of one of my elements. Can you show me a jQuery-free way of doing it?
ancestorElement:focus-within
? – TentedArray.from(document.querySelectorAll(selector)).some(node => node.contains(document.activeElement))
maybe. – Manizales:focus
or:focus-within
is better and easier. – Manizales