Detect when an element is ready in the DOM
JavaScript
Latest commit 0ea7043 Dec 15, 2017 @sindresorhus sindresorhus 2.2.1
Permalink
Failed to load latest commit information.
.editorconfig Meta tweaks Jun 1, 2017
.gitattributes Meta tweaks Jan 13, 2017
.gitignore Meta tweaks Oct 4, 2017
.npmrc Meta tweaks Oct 4, 2017
.travis.yml init Jul 4, 2016
index.js Minor tweaks Dec 15, 2017
license Meta tweaks Jun 1, 2017
package.json 2.2.1 Dec 15, 2017
readme.md Minor tweaks Dec 15, 2017
test.js Minor tweaks Dec 15, 2017

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.

elementReadyPromise#cancel()

Type: Function

Stops checking for the element to be ready. The cancelation is synchronous.

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

Based on p-cancelable.

Related

  • dom-loaded - Check when the DOM is loaded like DOMContentLoaded

License

MIT © Sindre Sorhus