Extends
Members
elements
- Source:
Example
container.elements // returns an array of Elements
first
- Source:
Example
container.first // returns a Node or null
firstElement
- Source:
Example
container.firstElement // returns an Element or null
index
- Source:
- Inherited From:
Position of the current Node from its parent.
Example
node.index // returns the index of the node or -1
innerHTML
- Source:
Return the innerHTML of the current Container as a String.
Example
container.innerHTML // returns a string of innerHTML
innerHTML
- Source:
Define the nodes of the current Container from a String.
Example
container.innerHTML = 'Hello <strong>world</strong>';
container.nodes.length; // 2
last
- Source:
Example
container.last // returns a Node or null
lastElement
- Source:
Example
container.lastElement // returns an Element or null
next
Example
node.next // returns null
nextElement
- Source:
- Inherited From:
Example
node.nextElement // returns an element or null
outerHTML
- Source:
Return the outerHTML of the current Container as a String.
Example
container.outerHTML // returns a string of outerHTML
outerHTML
- Source:
Replace the current Container from a String.
Example
container.outerHTML = 'Hello <strong>world</strong>';
previous
- Source:
- Inherited From:
Example
node.previous // returns a node or null
previousElement
- Source:
- Inherited From:
Example
node.previousElement // returns an element or null
root
Top-most ancestor from the current Node.
Example
node.root // returns the top-most node or the current node itself
sourceInnerHTML
- Source:
Return the stringified innerHTML from the source input.
sourceOuterHTML
- Source:
Return the stringified outerHTML from the source input.
textContent
- Source:
Return the text content of the current Container as a String.
textContent
- Source:
Methods
after(…nodes)
- Source:
- Inherited From:
Example
node.after(new Text({ data: 'Hello World' }))
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes to be inserted after the current Node. |
append(…nodes)
- Source:
- Inherited From:
Example
node.append(someOtherNode)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes to be inserted after the last child of the current Node. |
appendTo(parent)
- Source:
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
parent |
Container |
before(…nodes)
- Source:
- Inherited From:
Insert Nodes or new Text Nodes before the Node if it has a parent, returning the current Node.
Example
node.before(new Text({ data: 'Hello World' })) // returns the current node
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes to be inserted before the current Node. |
lastNth() → {Node|null}
- Source:
Example
container.lastNth(0) // returns a Node or null
Returns:
- Type
- Node | null
lastNthElement() → {Element|null}
- Source:
Example
container.lastNthElement(0) // returns an Element or null
Returns:
- Type
- Element | null
nth() → {Node|null}
- Source:
Example
container.nth(0) // returns a Node or null
Returns:
- Type
- Node | null
nthElement() → {Element|null}
- Source:
Return an Element child of the current Container by index, or null
if there is none.
Example
container.nthElement(0) // returns an Element or null
Returns:
- Type
- Element | null
prepend(…nodes)
- Source:
- Inherited From:
Example
node.prepend(someOtherNode)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node | string |
<repeatable> |
Any nodes inserted before the first child of the current Node. |
remove()
- Source:
- Inherited From:
Example
node.remove() // returns the current node
replaceAll(…nodes)
- Source:
Example
container.replaceAll(new Text({ data: 'Hello World' }))
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Array.<Node> |
<repeatable> |
Any nodes replacing the current children of the Container. |
replaceWith(…nodes)
- Source:
- Inherited From:
Example
node.replaceWith(someOtherNode) // returns the current node
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
nodes |
Node |
<repeatable> |
Any nodes replacing the current Node. |
visit(result, overrideVisitorsopt) → {ResultPromise}
- Source:
- Inherited From:
Transform the current Node and any descendants using visitors.
Examples
await node.visit(result)
await node.visit() // visit using the result of the current node
await node.visit(result, {
Element () {
// do something to an element
}
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
result |
Result | Result to be used by visitors. |
|
overrideVisitors |
Object |
<optional> |
Alternative visitors to be used in place of Result visitors. |
Returns:
- Type
- ResultPromise
walk(callback_or_filter, callback)
- Source:
Traverse the descendant Nodes of the current Container with a callback function, returning the current Container.
Examples
container.walk(node => {
console.log(node);
})
container.walk('*', node => {
console.log(node);
})
Walk only "section" Elements.
container.walk('section', node => {
console.log(node); // logs only Section Elements
})
container.walk(/^section$/, node => {
console.log(node); // logs only Section Elements
})
container.walk(
node => node.name.toLowerCase() === 'section',
node => {
console.log(node); // logs only Section Elements
})
Walk only Text.
container.walk('#text', node => {
console.log(node); // logs only Text Nodes
})
Parameters:
Name | Type | Description |
---|---|---|
callback_or_filter |
function | string | RegExp | Callback function, or a filter to reduce Nodes the callback is applied to. |
callback |
function | string | RegExp | Callback function when a filter is also specified. |
warn(result, text, optsopt)
Add a warning from the current Node.
Examples
node.warn(result, 'Something went wrong')
node.warn(result, 'Something went wrong', {
node: someOtherNode,
plugin: someOtherPlugin
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
result |
Result | Result the warning is being added to. |
|
text |
string | Message being sent as the warning. |
|
opts |
Object |
<optional> |
Additional information about the warning. |