@laserware/dominator
    Preparing search index...

    Function getAttribute

    • Attempts to get the attribute name from the target. If the value is found, it is coerced to a boolean if "true" or "false", a number if numeric, or the string value if a string. If not found, returns null.

      Type Parameters

      Parameters

      • target: null | Target

        Element, EventTarget, or CSS selector.

      • name: AttributeName<E>

        Name of the attribute to get.

      Returns null | V

      Value of type V or null if not found.

      We're returning null, rather than undefined to match the Element.getAttribute API.

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

      HTML

      <div
      id="example"
      role="slider"
      aria-valuemax="30"
      aria-label="Example"
      aria-disabled="false"
      >
      ...
      </div>

      Code

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

      getAttribute(element, "aria-label");
      // "Example"

      getAttribute(element, "aria-valuemax");
      // 30

      getAttribute(element, "aria-disabled");
      // false