Skip to content

docs: parse() always adds a wrapper node [#285] #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { parse } from 'node-html-parser';

const root = parse('<ul id="list"><li>Hello World</li></ul>');

// parse() adds a wrapper node, so the input data's first node is the root's first child node
console.log(root.firstChild.structure);
// ul#list
// li
Expand Down Expand Up @@ -74,7 +75,7 @@ var root = HTMLParser.parse('<ul id="list"><li>Hello World</li></ul>');

### parse(data[, options])

Parse the data provided, and return the root of the generated DOM.
Parse the data provided, wrap the result in a new node, and return the root of the generated DOM.

- **data**, data to parse
- **options**, parse options
Expand Down Expand Up @@ -349,11 +350,11 @@ Get all child elements, so all child nodes of type HTMLELement.

### firstChild

Get first child node. `undefined` if the node has no children.
Get first child node of the wrapper node added by `parse()`. `undefined` if the node has no children.

### lastChild

Get last child node. `undefined` if the node has no children.
Get last child node of the wrapper node added by `parse()`. `undefined` if the node has no children.

### firstElementChild

Expand Down