A lightweight utility for detecting and handling DOM mutations using MutationObserver.
This utility was inspired by the MutationObserver implementation from BigCommerce's Guide to Checkout Customisation.
- Node.js >=16.0.0
npm install @space48/mutation-ready
import { mutationReady } from "@space48/mutation-ready";
// Wait for an element to appear in the DOM
mutationReady(".my-element", (element) => {
// Do something with the element
console.log("Element is ready:", element);
});
- Lightweight and dependency-free
- TypeScript support
- Uses MutationObserver for efficient DOM monitoring
- Handles dynamic content loading
- WebKit compatibility
selector
: CSS selector string to match elementscallback
: Function to be called when matching elements are found- Each element will only trigger the callback once
MIT