Detect element availability on the initial page load and those dynamically appended to the DOM
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

ready

Version Badge Build Status Dependencies License File Size

Watch for specific element availability on initial page load as well as dynamically appended elements via mutation observers. Please refer to the blog post to read more.

Usage

Provide a selector string for the element(s) you want to target as the first argument and a callback function as the second argument. It returns a function that stops observing for new elements only for that particular selector/callback combination:

const off = ready('.foo', (element) => {
    off(); // Stop observing for .foo elements
});

When any element matching the selector becomes available, the callback is invoked in the context of the element as well as passing it as the only parameter. If multiple elements are found, the callback is invoked in succession for each element in document order.

Installation

Ready is CommonJS and AMD compatible with no dependencies. You can download the development or minified version, or install it in one of the following ways:

npm install ryanmorr/ready

bower install ryanmorr/ready

Tests

Open test/runner.html in your browser or test with PhantomJS by issuing the following commands:

npm install
npm install -g gulp
gulp test

License

This project is dedicated to the public domain as described by the Unlicense.