Skip to content

DocumentFragment.find method

DocumentFragment › find

Official

Finds the first descendant element that matches the selector.

Signature:

find(selector: string): Element | null

Parameters:

Parameter Type Description
selector string The selector to find the element with.

Returns: Element | nullThe first descendant element that matches the selector, or null if no match is found.

Remarks:

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

Example:

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