• Searches for all focusable elements in either the Document (if no parent specified) or the specified parent.

    See this article for how focusable elements are determined.

    Parameters

    • Optionalparent: null | Target = document

      Optional Element or EventTarget for parent.

    Returns HTMLElement[]

    Array of focusable elements in the optionally specified parent.

    HTML

    <form action="" method="get" class="form-example">
    <div class="form-example">
    <label for="name">Enter your name: </label>
    <input type="text" name="name" id="name" required />
    </div>
    <div class="form-example">
    <label for="email">Enter your email: </label>
    <input type="email" name="email" id="email" required />
    </div>
    <div class="form-example">
    <input type="submit" value="Subscribe!" />
    </div>
    </form>

    Code

    const items = findAllFocusable("form");
    // [<input id="name">, <input id="email">, <input type="submit">]