kpripper-lib
v1.1.8
Published
useful utils
Downloads
54
Readme
kpripper-lib
kpripper-lib is a JavaScript library that provides a utility function, waitForElement, which allows you to wait for a specific DOM element to appear in the document. This is particularly useful for scenarios where elements are dynamically added to the DOM.
Installation
You can install the library using npm:
npm install kpripper-libUsage
CommonJS
const { waitForElement } = require("kpripper-lib")ES Module
import { waitForElement } from "kpripper-lib"Example
const element = await waitForElement(".my-class", {
scope: document.querySelector(".container"),
timeout: 10000,
})API
waitForElement(selector, options)
- selector: A string representing the CSS selector to match the element.
- options: An optional object to configure the search.
- scope: The DOM element or document to search within (default is
document). - timeout: The maximum time to wait in milliseconds (default is
5000).
- scope: The DOM element or document to search within (default is
domWatcher
The domWatcher is a singleton instance that helps you watch for DOM elements appearing and disappearing from the document.
Examples
// Example 1: Watching for an element to appear
domWatcher.watch(".my-class", (element) => {
console.log("Element appeared:", element);
});
// Example 2: Watching for an element to disappear
domWatcher.watch(".my-class", null, (element) => {
console.log("Element disappeared:", element);
});License
This project is licensed under the MIT License.
