• Checks if the target has all of the attributes that match the search criteria.

    Type Parameters

    • TN extends TagName = "*"

      Tag name of the Element representation of target.

    Parameters

    • target: null | Target<TN>

      Element, EventTarget, or CSS selector.

    • search: AttributesSearch<TN>

      Array of attribute names or attributes filter object to check for.

    Returns boolean

    true if the target matches all search criteria.

    elements!InvalidElementError if the specified target wasn't found.

    HTML

    <div id="example" aria-hidden="true" inert>
    Example
    </div>

    Code

    const element = findElement("#example")!;

    hasAllAttributes(element, ["aria-hidden"]);
    // true

    hasAllAttributes(element, ["aria-hidden", "missing"]);
    // false ("missing" does not exist)

    hasAllAttributes(element, {
    "aria-hidden": true,
    inert: null,
    });
    // true