Elements With Event Handlers Used to Emulate Links

Elements With Event Handlers Used to Emulate Links

WCAG Focus: WCAG 4.1.2 (A), 2.1.1 (A)

Page builders and custom JavaScript widgets sometimes attach onclick handlers to <div>, <span>, or <img> tags to navigate users to a new page. Unlike native <a> elements, generic elements are excluded from keyboard Tab focus, lack Enter activation, and are not announced as links to screen readers.

Why This Pattern Violates WCAG

WCAG 2.1.1 Keyboard (Level A) fails because keyboard-only users cannot reach or activate a clickable <div> unless tabindex and keydown handlers are added manually.

WCAG 4.1.2 Name, Role, Value (Level A) fails because assistive technologies do not recognize the element as a link or button.

Code Comparison

Inaccessible Clickable Span Emulating a Link

<span class="cta-btn" onclick="location.href='/contact/'">Contact Us</span>

Compliant Native Anchor Tag

<a href="/contact/" class="cta-btn">Contact Us</a>

How to Fix It in WordPress

  • Use <a href="…"> for navigation and <button type="button"> for in-page actions.
  • If a legacy widget cannot be rewritten to native HTML, add role="link" or role="button", tabindex="0", and Enter/Space keyboard handlers.

Finding This Issue Automatically

Custom WordPress shortcodes and page-builder modules often turn <div> containers into pseudo-links with inline onclick scripts. Along with flagging them, the WP ADA Compliance Check plugin will automatically fix this issue by adding role and tabindex attributes (plus onkeypress handlers) to elements with event handlers that emulate links.

WCAG References & Supporting Materials

WCAG Success Criteria

Supporting Documentation & Guides

Subscribe

Subscribe to receive daily Web Accessibility - Did you know? articles in your inbox.

Cart Accessibility Tools
hide