observable-wait-for-element
v1.0.4
Published
Wait for an element to be present in the DOM
Readme
wait-for-element
A lightweight RxJS utility that polls for DOM elements until they become available.
Installation
npm install observable-wait-for-elementyarn add observable-wait-for-elementFeatures
- 🔄 Polling-based element detection
- ⚡ RxJS-powered
- ⏱️ Configurable timeout and refresh intervals
- 🎯 Custom root element support
- 🚫 Automatic error handling for timeouts
Usage
import waitForElement$ from 'observable-wait-for-element';
// Basic usage
waitForElement$({ query: '#my-element' })
.subscribe({
next: (element) => {
if (element) {
console.log('Element found!', element);
}
},
error: (error) => console.error('Element not found:', error)
});
// Advanced usage with custom options
waitForElement$({
query: '.dynamic-content',
root: document.getElementById('app'),
ticks: 20, // Wait longer
refreshInterval: 200 // Check every 200ms
}).subscribe({
next: (element) => {
if (element) {
// Do something with the element
}
}
});