Detect when an element is ready in the DOM
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.editorconfig Meta tweaks Jun 1, 2017
.gitattributes Require Node.js 6 May 18, 2018
.gitignore Meta tweaks Oct 4, 2017
.npmrc Meta tweaks Oct 4, 2017
.travis.yml Require Node.js 6 May 18, 2018
index.js Require Node.js 6 May 18, 2018
license Meta tweaks Jun 1, 2017
package.json 3.0.0 May 18, 2018
readme.md Minor tweaks Dec 15, 2017
test.js Require Node.js 6 May 18, 2018

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