@laserware/dominator
    Preparing search index...

    Function hasAttribute

    • Checks if the target has the attribute name. If a value is specified, checks that the values match.

      Type Parameters

      Parameters

      • target: null | Target

        Element, EventTarget, or CSS selector.

      • name: AttributeName<E>

        Name of the attribute to check for.

      • Optionalvalue: AttributeValue

        Optional attribute value to check for.

      Returns boolean

      true if the attribute name is present and value matches (if specified).

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

      HTML

      <button id="example" aria-pressed="true" aria-label="Example">
      Example
      </button>

      Code

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

      hasAttribute(element, "aria-pressed");
      // true

      hasAttribute(element, "aria-pressed", "true");
      // false ("true" cannot be a string, must be the boolean value `true`)

      hasAttribute(element, "aria-label", "Example");
      // true