wetoolaguer / ready

Detect element availability on the initial page load and those dynamically appended to the DOM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Detect element availability on the initial page load and those dynamically appended to the DOM

License:The Unlicense


Languages

Language:JavaScript 99.9%Language:HTML 0.1%