Documentation/HtmlNode
classWORKER

HtmlNode

js/foo_uie_jsplitter.js:7787

Lightweight DOM-like HTML node.

HtmlNode can represent an element node, text node, comment node, or another parsed DOM node type. Some operations, such as attributes and class checks, only make sense for element nodes.
NOTE: HtmlNode objects keep the underlying native document alive while they exist.

propertyWORKERreadonly

childNodes

js/foo_uie_jsplitter.js:7925
childNodes: Array<HtmlNode>

All child nodes, including element nodes, text nodes and comments.

Example

const doc = utils.ParseHtml("<p>Hello <b>world</b></p>");
const p = doc.querySelector("p");
console.log(p.childNodes.length); // 2
propertyWORKERreadonly

children

js/foo_uie_jsplitter.js:7939
children: Array<HtmlNode>

Child element nodes only.
Text nodes and comments are skipped.

Example

const doc = utils.ParseHtml("<p>Hello <b>world</b></p>");
const p = doc.querySelector("p");
console.log(p.children.length); // 1
console.log(p.children[0].tagName); // "b"
propertyWORKERreadonly

className

js/foo_uie_jsplitter.js:7830
className: string

Value of the class attribute.
For non-element nodes, or elements without a class attribute, this is an empty string.

Example

const doc = utils.ParseHtml("<p class='album featured'>Title</p>");
if (doc) {
    const p = doc.querySelector("p");
    console.log(p.className); // "album featured"
}
propertyWORKERreadonly

firstChild

js/foo_uie_jsplitter.js:7902
firstChild: ?HtmlNode

First child node.
Important: this can be a text node or comment, not necessarily an element.
Whitespace-only text nodes are preserved. Use JSON.stringify(node.textContent) while debugging if you need to see line breaks, tabs, and spaces explicitly.

Use children[0] or querySelector when you need an element.

Example

const doc = utils.ParseHtml("<li>text before link <a href='https://example.com'>Link</a></li>");
const li = doc.querySelector("li");

console.log(JSON.stringify(li.firstChild.textContent)); // "text before link "

const a = li.querySelector("a");
console.log(a.getAttribute("href")); // "https://example.com"
propertyWORKERreadonly

innerHTML

js/foo_uie_jsplitter.js:7874
innerHTML: string

Serialized HTML markup inside this node.

Example

const doc = utils.ParseHtml("<p>Hello <b>world</b></p>");
const p = doc.querySelector("p");
console.log(p.innerHTML); // "Hello <b>world</b>"
propertyWORKERreadonly

innerText

js/foo_uie_jsplitter.js:7864
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.

propertyWORKERreadonly

isElement

js/foo_uie_jsplitter.js:7797
isElement: boolean

Whether this node is an element node.
Element nodes are tags such as <div>, <a>, <p>, <body>.
Text nodes and comments are not element nodes.

Example

const doc = utils.ParseHtml("<p>Hello <b>world</b></p>");
const p = doc ? doc.querySelector("p") : null;
if (p) {
    console.log(p.isElement); // true
    console.log(p.firstChild ? p.firstChild.isElement : null); // false
}
propertyWORKERreadonly

outerHTML

js/foo_uie_jsplitter.js:7888
outerHTML: string

Serialized HTML markup of this node itself.

Example

const doc = utils.ParseHtml("<p>Hello <b>world</b></p>");
const p = doc.querySelector("p");
console.log(p.outerHTML); // "<p>Hello <b>world</b></p>"
propertyWORKERreadonly

tagName

js/foo_uie_jsplitter.js:7816
tagName: string

Lowercase tag name for element nodes.
For non-element nodes, this is an empty string.

Example

const doc = utils.ParseHtml("<BODY><P>Hello</P></BODY>");
if (doc) console.log(doc.body.tagName); // "body"
propertyWORKERreadonly

textContent

js/foo_uie_jsplitter.js:7847
textContent: string

Text content of this node and its descendants.
Whitespace is returned as it exists in parsed text nodes.

Example

const doc = utils.ParseHtml("<p>Hello <b>world</b></p>");
if (doc) {
    const p = doc.querySelector("p");
    console.log(p ? p.textContent : null); // "Hello world"
}
methodWORKER

getAttribute

js/foo_uie_jsplitter.js:7955
getAttribute(name)

Returns an attribute value.
For missing attributes or non-element nodes, returns an empty string.

Parameters

NameTypeDescription
namestring

Attribute name.

Returns

string —

Attribute value, or empty string.

Example

const doc = utils.ParseHtml("<a href='https://example.com'>Link</a>");
const a = doc.querySelector("a");
console.log(a.getAttribute("href")); // "https://example.com"
methodWORKER

getElementsByTagName

js/foo_uie_jsplitter.js:8046
getElementsByTagName(tagName)

Returns all descendant elements with the specified tag name.
Use "*" to return all descendant elements.

Parameters

NameTypeDescription
tagNamestring

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'>One</a><a href='/two'>Two</a></p>");
const p = doc.querySelector("p");
const links = p.getElementsByTagName("a");

console.log(links.length); // 2
methodWORKER

hasAttribute

js/foo_uie_jsplitter.js:7971
hasAttribute(name)

Checks whether an element has an attribute.
For non-element nodes, returns false.

Parameters

NameTypeDescription
namestring

Attribute name.

Returns

boolean

Example

const doc = utils.ParseHtml("<a href='https://example.com'>Link</a>");
const a = doc.querySelector("a");
console.log(a.hasAttribute("href")); // true
console.log(a.hasAttribute("title")); // false
methodWORKER

hasClass

js/foo_uie_jsplitter.js:7988
hasClass(className)

Checks whether the element has a CSS class token.
This checks class tokens, not arbitrary substrings.
For example, hasClass("album") matches class="album featured", but not class="album-list".
For non-element nodes, returns false.

Parameters

NameTypeDescription
classNamestring

Class token to check.

Returns

boolean

Example

const doc = utils.ParseHtml("<li class='album featured'>Title</li>");
const li = doc.querySelector("li");

console.log(li.hasClass("album")); // true
console.log(li.hasClass("featured")); // true
console.log(li.hasClass("album-list")); // false
methodWORKER

querySelector

js/foo_uie_jsplitter.js:8009
querySelector(selector)

Returns the first descendant element matching a CSS selector.

Parameters

NameTypeDescription
selectorstring

CSS selector.

Returns

?HtmlNode —

First matching node, or null if nothing matches.

Example

const doc = utils.ParseHtml("<li>text <a href='https://example.com'>Link</a></li>");
const li = doc.querySelector("li");
const a = li.querySelector("a[href]");

if (a) {
    console.log(a.getAttribute("href")); // "https://example.com"
}
methodWORKER

querySelectorAll

js/foo_uie_jsplitter.js:8028
querySelectorAll(selector)

Returns all descendant elements matching a CSS selector.
The returned value is a regular JavaScript array.

Parameters

NameTypeDescription
selectorstring

CSS selector.

Returns

Array<HtmlNode> —

Array of matching nodes. Empty array if nothing matches.

Example

const doc = utils.ParseHtml("<ul><li class='album'>A</li><li class='album featured'>B</li></ul>");
const list = doc.querySelector("ul");
const albums = list.querySelectorAll(".album");

console.log(albums.length); // 2