Documentation/HtmlNode
class

HtmlNode

js/foo_uie_jsplitter.js:5430

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.

propertyreadonly

childNodes

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

children

js/foo_uie_jsplitter.js:5572
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"
propertyreadonly

className

js/foo_uie_jsplitter.js:5470
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"
}
propertyreadonly

firstChild

js/foo_uie_jsplitter.js:5537
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"
propertyreadonly

innerHTML

js/foo_uie_jsplitter.js:5511
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>"
propertyreadonly

innerText

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

propertyreadonly

isElement

js/foo_uie_jsplitter.js:5439
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
}
propertyreadonly

outerHTML

js/foo_uie_jsplitter.js:5524
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>"
propertyreadonly

tagName

js/foo_uie_jsplitter.js:5457
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"
propertyreadonly

textContent

js/foo_uie_jsplitter.js:5486
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"
}
method

getAttribute

js/foo_uie_jsplitter.js:5587
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"
method

getElementsByTagName

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

hasAttribute

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

hasClass

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

querySelector

js/foo_uie_jsplitter.js:5638
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"
}
method

querySelectorAll

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