The CSS selector string or HTMLElement to wait for.
Optional
options: {Optional configuration:
A promise that resolves with the HTMLElement when visible, or rejects on timeout.
// ES Module
import { waitForVisibleElement } from '@bnidev/js-utils'
// CommonJS
const { waitForVisibleElement } = require('@bnidev/js-utils')
// Wait for an element with ID 'myElement' to become visible
waitForVisibleElement('myElement')
.then((el) => {
console.log('Element is visible:', el)
})
.catch((error) => {
console.error('Error:', error)
})
// Wait for an element with ID 'myElement' with custom options
waitForVisibleElement('myElement', {
timeout: 5000,
interval: 100,
displayCheck: (style) => style.display !== 'none' && style.visibility !== 'hidden'
})
.then((el) => {
console.log('Element is visible:', el)
})
.catch((error) => {
console.error('Error:', error)
})
Waits for an element with the specified ID to become visible in the DOM.
The function repeatedly checks for the element's presence and visibility, using the provided or default display check, until the element is visible or the timeout is reached.