Tweakr
    Preparing search index...

    Function focusElement

    • Focuses the first element matching a CSS selector.

      Skips disabled elements. Optionally adds a temporary tabindex for non-focusable elements.

      Parameters

      • selector: string

        CSS selector to locate the element.

      • Optionaloptions: FocusOptions & { fallbackTabIndex?: boolean }

        Focus options.

        • preventScroll

          Prevent scrolling when focusing. Defaults to false.

        • fallbackTabIndex

          Add tabindex="-1" if element is not focusable. Defaults to false.

        • OptionalfallbackTabIndex?: boolean

          Add tabindex="-1" if element is not focusable. Defaults to false.

      Returns boolean

      true if element was found and focused, false otherwise.

      focusElement("#username"); // Focuses input with id="username"

      focusElement("#submitBtn", { preventScroll: true, fallbackTabIndex: true });

      1.2.0