Ryanmorr Ready Save

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

Project README

ready

Version Badge License Build Status

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

Install

Download the CJS, ESM, UMD versions or install via NPM:

npm install @ryanmorr/ready

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 stop = ready('.foo', (element) => {
    stop(); // 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.

Alternatively, provide just the callback function as the only argument to add a generic DOM ready event listener:

ready((doc) => {
    // The DOM is ready
});

License

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

Open Source Agenda is not affiliated with "Ryanmorr Ready" Project. README Source: ryanmorr/ready
Stars
79
Open Issues
0
Last Commit
1 month ago
Repository

Open Source Agenda Badge

Open Source Agenda Rating