body: ?HtmlNode
The document <body> element.
Example
let doc = utils.ParseHtml("<html><body><p>Hello</p></body></html>");
if (doc && doc.body) console.log(doc.body.innerHTML);
documentElement: ?HtmlNode
Root document element, usually the <html> element.
Example
let doc = utils.ParseHtml("<html><body>Hello</body></html>");
if (doc) console.log(doc.documentElement.tagName);
innerText: string
Alias of textContent.
Since this parser has no browser layout engine, innerText does not emulate CSS visibility, rendered line wrapping, or layout-dependent text extraction.
textContent: string
Text content of the document body.
If the document has no body, this falls back to the root element text.
Whitespace is returned as it exists in the parsed text nodes.
Example
let doc = utils.ParseHtml("<html><body><p>Hello <b>world</b></p></body></html>");
if (doc) console.log(doc.textContent);
getElementsByTagName(tagName)
Returns all descendant elements with the specified tag name.
Use "*" to return all descendant elements.
Parameters
| Name | Type | Description |
tagName | string | Tag name, for example "a", "div", "section" or "*". |
Returns
Array<HtmlNode> —
Array of matching nodes. Empty array if nothing matches.
Example
const doc = utils.ParseHtml("<p><a href='https://example.com'>Link</a></p>");
const links = doc ? doc.getElementsByTagName("a") : [];
console.log(links.length);
querySelectorAll(selector)
Returns all elements matching a CSS selector.
The returned value is a regular JavaScript array.
Parameters
| Name | Type | Description |
selector | string | CSS selector. |
Returns
Array<HtmlNode> —
Array of matching nodes. Empty array if nothing matches.
Example
let doc = utils.ParseHtml("<ul><li class='album'>A</li><li class='album'>B</li></ul>");
let albums = doc ? doc.querySelectorAll(".album") : [];
console.log(albums.length);