Documentation/HtmlNode
classWORKER

HtmlNode

js/foo_uie_jsplitter.js:7827

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:7965
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:7979
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:7870
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:7942
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:7914
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:7904
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:7837
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:7928
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:7856
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:7887
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:7995
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:8086
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:8011
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:8028
hasClass(className)

Checks whether the element has a CSS class token.
This checks class tokens, not arbitrary substrings.
For example, passing "album" to hasClass 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:8049
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:8068
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