Function selectorQuery

  • This is a wrapper around document.selectorQuery().

    This looks for elements matching the query string. This ensures that exactly one element matches the query string, and that element has the expected type.

    Type Parameters

    • T extends Element

    Parameters

    • selector: string

      What to search for. E.g. "#main p:first-child"

    • ty: (new () => T)

      The expected type. E.g. HTMLParagraphElement

        • new (): T
        • Returns T

    • start: Pick<Document, "querySelectorAll"> = document

      Where to look for the element. Defaults to window.document.

    Returns T

    The new element.

    If we don't find the object, we find multiple matching objects or we find an object of the wrong type.

    I created this poorly named version by mistake. querySelector does the same thing, but uses the same naming convention as the DOM.