Skip to content

DocumentFragment

Defined in: src/full-types.d.ts:481

obsidian-typings/src/global/augmentations/DocumentFragment.d.ts

  • Node.NonElementParentNode.ParentNode

readonly ATTRIBUTE_NODE: 2

Defined in: lib.dom.d.ts:17158

ParentNode.ATTRIBUTE_NODE


readonly baseURI: string

Defined in: lib.dom.d.ts:17027

Returns node’s node document’s document base URL.

MDN Reference

ParentNode.baseURI


readonly CDATA_SECTION_NODE: 4

Defined in: lib.dom.d.ts:17162

node is a CDATASection node.

ParentNode.CDATA_SECTION_NODE


readonly childElementCount: number

Defined in: lib.dom.d.ts:17745

MDN Reference

ParentNode.childElementCount


readonly childNodes: NodeListOf<ChildNode>

Defined in: lib.dom.d.ts:17033

Returns the children.

MDN Reference

ParentNode.childNodes


readonly children: HTMLCollection

Defined in: lib.dom.d.ts:17751

Returns the child elements.

MDN Reference

ParentNode.children


readonly COMMENT_NODE: 8

Defined in: lib.dom.d.ts:17168

node is a Comment node.

ParentNode.COMMENT_NODE


constructorWin: Window

Defined in: src/full-types.d.ts:1257

Global window object.

Node.constructorWin


doc: Document

Defined in: src/full-types.d.ts:1263

The document this node belongs to, or the global document.

Node.doc


readonly DOCUMENT_FRAGMENT_NODE: 11

Defined in: lib.dom.d.ts:17174

node is a DocumentFragment node.

ParentNode.DOCUMENT_FRAGMENT_NODE


readonly DOCUMENT_NODE: 9

Defined in: lib.dom.d.ts:17170

node is a document.

ParentNode.DOCUMENT_NODE


readonly DOCUMENT_POSITION_CONTAINED_BY: 16

Defined in: lib.dom.d.ts:17185

Set when other is a descendant of node.

ParentNode.DOCUMENT_POSITION_CONTAINED_BY


readonly DOCUMENT_POSITION_CONTAINS: 8

Defined in: lib.dom.d.ts:17183

Set when other is an ancestor of node.

ParentNode.DOCUMENT_POSITION_CONTAINS


readonly DOCUMENT_POSITION_DISCONNECTED: 1

Defined in: lib.dom.d.ts:17177

Set when node and other are not in the same tree.

ParentNode.DOCUMENT_POSITION_DISCONNECTED


readonly DOCUMENT_POSITION_FOLLOWING: 4

Defined in: lib.dom.d.ts:17181

Set when other is following node.

ParentNode.DOCUMENT_POSITION_FOLLOWING


readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32

Defined in: lib.dom.d.ts:17186

ParentNode.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC


readonly DOCUMENT_POSITION_PRECEDING: 2

Defined in: lib.dom.d.ts:17179

Set when other is preceding node.

ParentNode.DOCUMENT_POSITION_PRECEDING


readonly DOCUMENT_TYPE_NODE: 10

Defined in: lib.dom.d.ts:17172

node is a doctype.

ParentNode.DOCUMENT_TYPE_NODE


readonly ELEMENT_NODE: 1

Defined in: lib.dom.d.ts:17157

node is an element.

ParentNode.ELEMENT_NODE


readonly ENTITY_NODE: 6

Defined in: lib.dom.d.ts:17164

ParentNode.ENTITY_NODE


readonly ENTITY_REFERENCE_NODE: 5

Defined in: lib.dom.d.ts:17163

ParentNode.ENTITY_REFERENCE_NODE


readonly firstChild: null | ChildNode

Defined in: lib.dom.d.ts:17039

Returns the first child.

MDN Reference

ParentNode.firstChild


readonly firstElementChild: null | Element

Defined in: lib.dom.d.ts:17757

Returns the first child that is an element, and null otherwise.

MDN Reference

ParentNode.firstElementChild


readonly isConnected: boolean

Defined in: lib.dom.d.ts:17045

Returns true if node is connected and false otherwise.

MDN Reference

ParentNode.isConnected


readonly lastChild: null | ChildNode

Defined in: lib.dom.d.ts:17051

Returns the last child.

MDN Reference

ParentNode.lastChild


readonly lastElementChild: null | Element

Defined in: lib.dom.d.ts:17763

Returns the last child that is an element, and null otherwise.

MDN Reference

ParentNode.lastElementChild


readonly nextSibling: null | ChildNode

Defined in: lib.dom.d.ts:17057

Returns the next sibling.

MDN Reference

ParentNode.nextSibling


readonly nodeName: string

Defined in: lib.dom.d.ts:17063

Returns a string appropriate for the type of node.

MDN Reference

ParentNode.nodeName


readonly nodeType: number

Defined in: lib.dom.d.ts:17069

Returns the type of node.

MDN Reference

ParentNode.nodeType


nodeValue: null | string

Defined in: lib.dom.d.ts:17071

MDN Reference

ParentNode.nodeValue


readonly NOTATION_NODE: 12

Defined in: lib.dom.d.ts:17175

ParentNode.NOTATION_NODE


readonly ownerDocument: null | Document

Defined in: lib.dom.d.ts:17077

Returns the node document. Returns null for documents.

MDN Reference

ParentNode.ownerDocument


readonly parentElement: null | HTMLElement

Defined in: lib.dom.d.ts:17083

Returns the parent element.

MDN Reference

ParentNode.parentElement


readonly parentNode: null | ParentNode

Defined in: lib.dom.d.ts:17089

Returns the parent.

MDN Reference

ParentNode.parentNode


readonly previousSibling: null | ChildNode

Defined in: lib.dom.d.ts:17095

Returns the previous sibling.

MDN Reference

ParentNode.previousSibling


readonly PROCESSING_INSTRUCTION_NODE: 7

Defined in: lib.dom.d.ts:17166

node is a ProcessingInstruction node.

ParentNode.PROCESSING_INSTRUCTION_NODE


readonly TEXT_NODE: 3

Defined in: lib.dom.d.ts:17160

node is a Text node.

ParentNode.TEXT_NODE


textContent: null | string

Defined in: lib.dom.d.ts:17097

MDN Reference

ParentNode.textContent


win: Window

Defined in: src/full-types.d.ts:1269

The window object this node belongs to, or the global window.

Node.win

addEventListener(type, callback, options?): void

Defined in: lib.dom.d.ts:8876

Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options’s capture.

When set to true, options’s capture prevents callback from being invoked when the event’s eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event’s eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event’s eventPhase attribute value is AT_TARGET.

When set to true, options’s passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

When set to true, options’s once indicates that the callback will only be invoked once after which the event listener will be removed.

If an AbortSignal is passed for options’s signal, then the event listener will be removed when signal is aborted.

The event listener is appended to target’s event listener list and is not appended if it has the same type, callback, and capture.

MDN Reference

string

null | EventListenerOrEventListenerObject

boolean | AddEventListenerOptions

void

ParentNode.addEventListener


append(…nodes): void

Defined in: lib.dom.d.ts:17771

Inserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes.

Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

MDN Reference

…(string | Node)[]

void

ParentNode.append


appendChild<T>(node): T

Defined in: lib.dom.d.ts:17099

MDN Reference

T extends Node

T

T

ParentNode.appendChild


appendText(val): void

Defined in: src/full-types.d.ts:1284

Appends a text node to the node.

string

The text to append.

void

const parent = createEl('p');
parent.createEl('strong', { text: 'foo' });
parent.appendText('bar');
console.log(parent); // <p><strong>foo</strong>bar</p>

Node.appendText


cloneNode(subtree?): Node

Defined in: lib.dom.d.ts:17105

Returns a copy of node. If deep is true, the copy also includes the node’s descendants.

MDN Reference

boolean

Node

ParentNode.cloneNode


compareDocumentPosition(other): number

Defined in: lib.dom.d.ts:17111

Returns a bitmask indicating the position of other relative to node.

MDN Reference

Node

number

ParentNode.compareDocumentPosition


contains(other): boolean

Defined in: lib.dom.d.ts:17117

Returns true if other is an inclusive descendant of node, and false otherwise.

MDN Reference

null | Node

boolean

ParentNode.contains


createDiv(o?, callback?): HTMLDivElement

Defined in: src/full-types.d.ts:1300

Creates a new <div> element.

The options object.

string | DomElementInfo

(el) => void

A callback function to be called when the element is created.

HTMLDivElement

The created element.

document.body.createDiv({ text: 'foo' }, (div) => {
div.createEl('strong', { text: 'bar' });
});

Node.createDiv


createEl<K>(tag, o?, callback?): HTMLElementTagNameMap[K]

Defined in: src/full-types.d.ts:1318

Create an element and append it to this node.

K extends keyof HTMLElementTagNameMap

The type of the element to create.

K

The tag name of the element to create.

The options object.

string | DomElementInfo

(el) => void

A callback function to be called when the element is created.

HTMLElementTagNameMap[K]

The created element.

document.body.createEl('p', { text: 'foo' }, (div) => {
div.createEl('strong', { text: 'bar' });
});

Node.createEl


createSpan(o?, callback?): HTMLSpanElement

Defined in: src/full-types.d.ts:1338

Creates a new <span> element.

The options object.

string | DomElementInfo

(el) => void

A callback function to be called when the element is created.

HTMLSpanElement

The created element.

document.body.createSpan({ text: 'foo' }, (span) => {
span.createEl('strong', { text: 'bar' });
});

Node.createSpan


createSvg<K>(tag, o?, callback?): SVGElementTagNameMap[K]

Defined in: src/full-types.d.ts:1355

Creates a new svg element such as <svg>, <circle>, <rect>, etc.

K extends keyof SVGElementTagNameMap

The type of the element to create.

K

The tag name of the element to create.

The options object.

string | SvgElementInfo

(el) => void

A callback function to be called when the element is created.

SVGElementTagNameMap[K]

The created element.

document.body.createSvg('svg', { cls: 'foo bar' }, (svg) => {
svg.createSvg('circle');
});
@official
#### Inherited from
[`Node`](/obsidian-typings/api/obsidian-typings/namespaces/global/interfaces/node/).[`createSvg`](/obsidian-typings/api/obsidian-typings/namespaces/global/interfaces/node/#createsvg)
***
### detach()
> **detach**(): `void`
Defined in: src/full-types.d.ts:1373
Detaches the node from the DOM.
#### Returns
`void`
#### Example
```ts
const node = document.body.createEl('p');
console.log(document.body.contains(node)); // true
node.detach();
console.log(document.body.contains(node)); // false

Node.detach


dispatchEvent(event): boolean

Defined in: lib.dom.d.ts:8882

Dispatches a synthetic event event to target and returns true if either event’s cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

MDN Reference

Event

boolean

ParentNode.dispatchEvent


empty(): void

Defined in: src/full-types.d.ts:1388

Empties the node.

void

const parent = createEl('p');
parent.createEl('strong');
console.log(parent.childNodes.length); // 1
parent.empty();
console.log(parent.childNodes.length); // 0

Node.empty


find(selector): null | Element

Defined in: src/full-types.d.ts:497

Finds the first descendant element that matches the selector.

string

The selector to find the element with.

null | Element

The first descendant element that matches the selector, or null if no match is found.

const fragment = createFragment();
fragment.createEl('strong', { cls: 'foo' });
console.log(fragment.find('.foo')); // <strong class="foo"></strong>
console.log(fragment.find('.bar')); // null

See bug https://forum.obsidian.md/t/bug-find-findall-findallself/98108.

findAll(selector): Element[]

Defined in: src/full-types.d.ts:515

Finds all descendant elements that match the selector.

string

The selector to find the elements with.

Element[]

An array of all descendant elements that match the selector.

const fragment = createFragment();
fragment.createEl('strong', { cls: 'foo' });
fragment.createEl('strong', { cls: 'foo' });
console.log(fragment.findAll('.foo')); // [<strong class="foo"></strong>, <strong class="foo"></strong>]
console.log(fragment.findAll('.bar')); // []

See bug https://forum.obsidian.md/t/bug-find-findall-findallself/98108.

getElementById(elementId): null | Element

Defined in: lib.dom.d.ts:17322

Returns the first element within node’s descendants whose ID is elementId.

MDN Reference

string

null | Element

NonElementParentNode.getElementById


getRootNode(options?): Node

Defined in: lib.dom.d.ts:17123

Returns node’s root.

MDN Reference

GetRootNodeOptions

Node

ParentNode.getRootNode


hasChildNodes(): boolean

Defined in: lib.dom.d.ts:17129

Returns whether node has children.

MDN Reference

boolean

ParentNode.hasChildNodes


indexOf(other): number

Defined in: src/full-types.d.ts:1397

Returns the index of the node or -1 if the node is not found.

Node

The node to find.

number

The index of the node or -1 if the node is not found.

Node.indexOf


insertAfter<T>(node, child): T

Defined in: src/full-types.d.ts:1418

Inserts a child node after the current node.

T extends Node

The type of the node to insert.

T

The node to insert.

The child node to insert after.

null | Node

T

The inserted node.

const parent = createEl('p');
const child1 = parent.createEl('strong', { text: '1' });
const child2 = parent.createEl('strong', { text: '2' });
const child3 = parent.createEl('strong', { text: '3' });
const newNode = createEl('em', { text: '4' });
parent.insertAfter(newNode, child2);
console.log(parent); // <p><strong>1</strong><strong>2</strong><em>4</em><strong>3</strong></p>

Node.insertAfter


insertBefore<T>(node, child): T

Defined in: lib.dom.d.ts:17131

MDN Reference

T extends Node

T

null | Node

T

ParentNode.insertBefore


instanceOf<T>(type): this is T

Defined in: src/full-types.d.ts:1436

Cross-window capable instanceof check, a drop-in replacement. for instanceof checks on DOM Nodes. Remember to also check for nulls when necessary.

T

The type of the instance.

() => T

The type to check.

this is T

true if the node is of the given type, false otherwise.

const node = createEl('p');
console.log(node.instanceOf(HTMLParagraphElement)); // true
console.log(node.instanceOf(HTMLSpanElement)); // false

Node.instanceOf


isDefaultNamespace(namespace): boolean

Defined in: lib.dom.d.ts:17133

MDN Reference

null | string

boolean

ParentNode.isDefaultNamespace


isEqualNode(otherNode): boolean

Defined in: lib.dom.d.ts:17139

Returns whether node and otherNode have the same properties.

MDN Reference

null | Node

boolean

ParentNode.isEqualNode


isSameNode(otherNode): boolean

Defined in: lib.dom.d.ts:17141

MDN Reference

null | Node

boolean

ParentNode.isSameNode


lookupNamespaceURI(prefix): null | string

Defined in: lib.dom.d.ts:17143

MDN Reference

null | string

null | string

ParentNode.lookupNamespaceURI


lookupPrefix(namespace): null | string

Defined in: lib.dom.d.ts:17145

MDN Reference

null | string

null | string

ParentNode.lookupPrefix


normalize(): void

Defined in: lib.dom.d.ts:17151

Removes empty exclusive Text nodes and concatenates the data of remaining contiguous exclusive Text nodes into the first of their nodes.

MDN Reference

void

ParentNode.normalize


prepend(…nodes): void

Defined in: lib.dom.d.ts:17779

Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes.

Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

MDN Reference

…(string | Node)[]

void

ParentNode.prepend


querySelector<K>(selectors): null | HTMLElementTagNameMap[K]

Defined in: lib.dom.d.ts:17785

Returns the first element that is a descendant of node that matches selectors.

MDN Reference

K extends keyof HTMLElementTagNameMap

K

null | HTMLElementTagNameMap[K]

ParentNode.querySelector

querySelector<K>(selectors): null | SVGElementTagNameMap[K]

Defined in: lib.dom.d.ts:17786

K extends keyof SVGElementTagNameMap

K

null | SVGElementTagNameMap[K]

ParentNode.querySelector

querySelector<K>(selectors): null | MathMLElementTagNameMap[K]

Defined in: lib.dom.d.ts:17787

K extends keyof MathMLElementTagNameMap

K

null | MathMLElementTagNameMap[K]

ParentNode.querySelector

querySelector<K>(selectors): null | HTMLElementDeprecatedTagNameMap[K]

Defined in: lib.dom.d.ts:17789

K extends keyof HTMLElementDeprecatedTagNameMap

K

null | HTMLElementDeprecatedTagNameMap[K]

ParentNode.querySelector

querySelector<E>(selectors): null | E

Defined in: lib.dom.d.ts:17790

E extends Element = Element

string

null | E

ParentNode.querySelector


querySelectorAll<K>(selectors): NodeListOf<HTMLElementTagNameMap[K]>

Defined in: lib.dom.d.ts:17796

Returns all element descendants of node that match selectors.

MDN Reference

K extends keyof HTMLElementTagNameMap

K

NodeListOf<HTMLElementTagNameMap[K]>

ParentNode.querySelectorAll

querySelectorAll<K>(selectors): NodeListOf<SVGElementTagNameMap[K]>

Defined in: lib.dom.d.ts:17797

K extends keyof SVGElementTagNameMap

K

NodeListOf<SVGElementTagNameMap[K]>

ParentNode.querySelectorAll

querySelectorAll<K>(selectors): NodeListOf<MathMLElementTagNameMap[K]>

Defined in: lib.dom.d.ts:17798

K extends keyof MathMLElementTagNameMap

K

NodeListOf<MathMLElementTagNameMap[K]>

ParentNode.querySelectorAll

querySelectorAll<K>(selectors): NodeListOf<HTMLElementDeprecatedTagNameMap[K]>

Defined in: lib.dom.d.ts:17800

K extends keyof HTMLElementDeprecatedTagNameMap

K

NodeListOf<HTMLElementDeprecatedTagNameMap[K]>

ParentNode.querySelectorAll

querySelectorAll<E>(selectors): NodeListOf<E>

Defined in: lib.dom.d.ts:17801

E extends Element = Element

string

NodeListOf<E>

ParentNode.querySelectorAll


removeChild<T>(child): T

Defined in: lib.dom.d.ts:17153

MDN Reference

T extends Node

T

T

ParentNode.removeChild


removeEventListener(type, callback, options?): void

Defined in: lib.dom.d.ts:8888

Removes the event listener in target’s event listener list with the same type, callback, and options.

MDN Reference

string

null | EventListenerOrEventListenerObject

boolean | EventListenerOptions

void

ParentNode.removeEventListener


replaceChild<T>(node, child): T

Defined in: lib.dom.d.ts:17155

MDN Reference

T extends Node

Node

T

T

ParentNode.replaceChild


replaceChildren(…nodes): void

Defined in: lib.dom.d.ts:17809

Replace all children of node with nodes, while replacing strings in nodes with equivalent Text nodes.

Throws a “HierarchyRequestError” DOMException if the constraints of the node tree are violated.

MDN Reference

…(string | Node)[]

void

ParentNode.replaceChildren


setChildrenInPlace(children): void

Defined in: src/full-types.d.ts:1455

Sets the children of the node.

Node[]

The children to set.

void

const parent = createEl('p');
const child1 = parent.createEl('strong', { text: '1' });
const child2 = parent.createEl('strong', { text: '2' });
const child3 = createEl('strong', { text: '3' });
parent.setChildrenInPlace([child1, child3]);
console.log(parent); // <p><strong>1</strong><strong>3</strong></p>

Node.setChildrenInPlace