Найти ближайший соответствующий узел const findClosestMatchingNode = (node, selector) => { for (let n = node; n.parentNode; n = n.parentNode) if (n.matches && n.matches(selector)) return n; return null; };JavaScriptCopy findClosestMatchingNode(document.querySelector('span'), 'body'); // bodyJavaScriptCopy Браузер JavaScript