Skip to content

Check when the DOM has loaded like `DOMContentLoaded`

License

Notifications You must be signed in to change notification settings

sindresorhus/dom-loaded

Repository files navigation

dom-loaded

Check when the DOM has loaded like DOMContentLoaded

Unlike DOMContentLoaded, this also works when included after the DOM was loaded.

Install

npm install dom-loaded

Usage

import domLoaded from 'dom-loaded';

await domLoaded;
console.log('The DOM is now loaded.');

API

domLoaded

Type: Promise<void>

The promise resolves when the DOM finishes loading or right away if the DOM has already loaded.

domLoaded.hasLoaded

Type: boolean

Synchronously check if the DOM has already finished loading.

domLoaded.signal

Type: AbortSignal

An AbortSignal that triggers when the DOM finishes loading or immediately if it has already loaded.

Related