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:
let htmlParser = new HtmlParser('<div>Test</div>');
let divElement = htmlParser.firstRootElement;
let htmlParser = new HtmlParser('<div>Test</div><p>Test 2</p>');
let elements = htmlParser.rootElements;
let htmlParser = new HtmlParser('<div>Test</div><p>Test 2</p>');
let elements = htmlParser.rootElements;
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');
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 |
firstRootElement: null | Element: * 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 |
querySelector(query: string): null | Element Query the body element of the parsed document using Element.querySelector. |
|
public |
querySelectorAll(query: string): NodeList Query the body element of the parsed document using Element.querySelectorAll. |
Public Constructors
Public Members
public get firstRootElement: null | Element: * source
Get the first root element of the parsed document.
public get rootElements: HTMLCollection: * source
Get the root elements of the parsed document.
Return:
HTMLCollection |