MCPcopy
hub / github.com/Bistutu/FluentRead / findMatchingElement

Function findMatchingElement

entrypoints/utils/common.ts:59–71  ·  view source on GitHub ↗
(element: Element, selector: string)

Source from the content-addressed store, hash-verified

57
58// 按 selector 查找匹配的元素,返回匹配的元素或 false
59export function findMatchingElement(element: Element, selector: string): Element | false {
60 // 检查当前元素是否匹配传入的选择器
61 if (element.matches(selector)) return element;
62
63 // 遍历父元素,直到找到匹配的元素或没有父元素
64 let parent = element.parentElement;
65 while (parent) {
66 if (parent.matches(selector)) return parent;
67 parent = parent.parentElement;
68 }
69
70 return false; // 未找到匹配元素
71}

Callers 1

compat.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected