Finds an element by its tag name.
(tagName: string, htmlContent: string)
| 88 | |
| 89 | /** Finds an element by its tag name. */ |
| 90 | function getElementByTagName(tagName: string, htmlContent: string): Element | null { |
| 91 | const document = parseHtml(htmlContent, {sourceCodeLocationInfo: true}); |
| 92 | const nodeQueue = [...document.childNodes]; |
| 93 | |
| 94 | while (nodeQueue.length) { |
| 95 | const node = nodeQueue.shift() as Element; |
| 96 | |
| 97 | if (node.nodeName.toLowerCase() === tagName) { |
| 98 | return node; |
| 99 | } else if (node.childNodes) { |
| 100 | nodeQueue.push(...node.childNodes); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return null; |
| 105 | } |
no test coverage detected