Skip to content
Detect when an element is ready in the DOM
JavaScript TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
.editorconfig
.gitattributes
.gitignore
.npmrc
.travis.yml
index.d.ts
index.js
index.test-d.ts
license
package.json
readme.md
test.js

readme.md

element-ready Build Status

Detect when an element is ready in the DOM

Install

$ npm install element-ready

Usage

const elementReady = require('element-ready');

(async () => {
	const element = await elementReady('#unicorn');

	console.log(element.id);
	//=> 'unicorn'
})();

API

elementReady(selector, options?)

Returns a promise for a matching element.

selector

Type: string

CSS selector.

options

Type: object

target

Type: Element | document
Default: document

The element that's expected to contain a match.

stopOnDomReady

Type: boolean
Default: true

Automatically stop checking for the element to be ready after the DOM ready event. The promise is then resolved to undefined.

timeout

Type: number
Default: Infinity

Milliseconds to wait before stopping the search and resolving the promise to undefined.

elementReadyPromise#stop()

Type: Function

Stop checking for the element to be ready. The stop is synchronous and the original promise is then resolved to undefined.

Calling it after the promise has settled or multiple times does nothing.

Related

  • dom-loaded - Check when the DOM is loaded like DOMContentLoaded
You can’t perform that action at this time.