Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use a short JavaScript check to find aria-describedby tokens that do not match an element ID in the same document. It catches missing targets only; it does not judge whether a description is useful or how a browser and assistive technology present it.

What the check detects

aria-describedby associates an element with descriptive content through one or more ID references. Each referenced target must be in the same DOM document, not on another page or an external resource. W3C WAI’s ARIA1 technique describes this same-document requirement.

The check below finds elements with the attribute, splits its value into whitespace-separated ID tokens, and reports every token for which the supplied root cannot find an element with that ID.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the minimal check

function findBrokenDescribedbyReferences(root = document) {
  const issues = [];

  for (const element of root.querySelectorAll('[aria-describedby]')) {
    const ids = element.getAttribute('aria-describedby').trim().split(/s+/).filter(Boolean);
    for (const id of ids) {
      if (!root.getElementById(id)) {
        issues.push({ element, id });
      }
    }
  }

  return issues;
}

Call findBrokenDescribedbyReferences() to scan the document, or pass a root that supports both querySelectorAll and getElementById to scan a subtree. The returned array contains one entry per unresolved token, with the element that contains the attribute and the missing ID. An empty array means this check found no unresolved references in the scanned root.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Interpret the results carefully

A found target may still be wrong

This check verifies that an ID target exists; it does not verify that the target contains additional, relevant information. W3C’s ARIA1 procedure treats the purpose of the referenced content as a separate check. Review the content and confirm it actually describes the relevant control or element.

Hidden targets are not automatically broken

A target can be hidden and still contribute to description computation. Do not report an ID as missing merely because its target is visually hidden. The WAI-ARIA Authoring Practices Guide explains that referenced description content may be hidden.

This is not a complete accessibility audit

The snippet does not detect duplicate IDs, assess whether a description is appropriate, or establish what a browser and assistive technology will expose. It is one narrow document-integrity check. W3C techniques describe example ways to meet WCAG; using this technique is not mandatory when the normative requirements are met another way.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.