Home Manual Reference Source
import HtmlParser from 'ievv_jsbase/lib/dom/HtmlParser'
public class | source

HtmlParser

HTML parser.

Takes a HTML string, creates a temporary DOM document, sets the HTML as innerHTML of the body of the temporary document, and provides methods for extracting elements from the temporary document.

Example:

Parse a single html element and get the Element
let htmlParser = new HtmlParser('<div>Test</div>');
let divElement = htmlParser.firstRootElement;
Parse multiple html elements
let htmlParser = new HtmlParser('<div>Test</div><p>Test 2</p>');
let elements = htmlParser.rootElements;
Parse multiple html elements and query them
let htmlParser = new HtmlParser('<div>Test</div><p>Test 2</p>');
let elements = htmlParser.rootElements;
Parse multiple html elements and query them
let htmlParser = new HtmlParser('<p>Test P 1</p><div>Test DIV</div><p>Test P 2</p>');
let divElement = htmlParser.querySelector('div');
let pElements = htmlParser.querySelectorAll('p');
Parse a full HTML document
let htmlParser = new HtmlParser('<html><body><p>Test</p></body></html>');
let pElement = htmlParser.firstRootElement;

Constructor Summary

Public Constructor
public

constructor(htmlString: string)

Member Summary

Public Members
public get

Get the first root element of the parsed document.

public get

rootElements: HTMLCollection: *

Get the root elements of the parsed document.

Method Summary

Public Methods
public

Query the body element of the parsed document using Element.querySelector.

public

Query the body element of the parsed document using Element.querySelectorAll.

Public Constructors

public constructor(htmlString: string) source

Params:

NameTypeAttributeDescription
htmlString string

The HTML string to parse.

Public Members

public get firstRootElement: null | Element: * source

Get the first root element of the parsed document.

Return:

null | Element

public get rootElements: HTMLCollection: * source

Get the root elements of the parsed document.

Return:

HTMLCollection

Public Methods

public querySelector(query: string): null | Element source

Query the body element of the parsed document using Element.querySelector.

Params:

NameTypeAttributeDescription
query string

The query.

Return:

null | Element

public querySelectorAll(query: string): NodeList source

Query the body element of the parsed document using Element.querySelectorAll.

Params:

NameTypeAttributeDescription
query string

The query.

Return:

NodeList