• Attempts to build a CSS selector string from the attribute name and value. Note that the value is coerced to a string and null excludes a value but only includes a name. If tagName is specified, it is included in the resulting selector.

    Note

    If you specify the optional E generic, you'll get autocomplete on the attributes for the element associated with that type.

    Type Parameters

    Parameters

    • name: AttributeName<E>

      Attribute name to include in the selector.

    • Optionalvalue: null | AttributeValue = undefined

      Optional attribute value to include in the selector.

    • OptionaltagName: string

      Optional tagName name to include in the selector.

    Returns string

    CSS selector based on the attribute name and optional value and tagName.

    InvalidAttributeError if the specified value could not be stringified.

    Name Only

    selectAttribute("disabled");
    // [disabled]

    Name and Value

    selectAttribute("disabled", true);
    // [disabled="true"]

    Name, Value, and Tag

    selectAttribute("disabled", true, "button");
    // button[disabled="true"]

    Name and Tag (No Value)

    selectAttribute("disabled", null, "button");
    // button[disabled]