@bnidev/js-utils
    Preparing search index...

    Function waitForVisibleElement

    • 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.

      Parameters

      • selectorOrElement: string | HTMLElement

        The CSS selector string or HTMLElement to wait for.

      • Optionaloptions: {
            displayCheck?: (style: CSSStyleDeclaration) => boolean;
            interval?: number;
            timeout?: number;
        }

        Optional configuration:

        • timeout: Maximum time to wait in milliseconds (default: 2000).
        • interval: Polling interval in milliseconds (default: 16).
        • displayCheck: Custom function to determine element visibility.

      Returns Promise<HTMLElement>

      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)
      })