Skip to main content

Explore Web Accessibility (a11y)

Back to navigation

Event Handling

Goal: attaching device-independent event handlers to interactive elements.

When using semantic html tags, these are generally taken care of. But when we use non-semantic html for tags for creating interactive elements, like using div to create buttons or dropdowns, etc., we need to attach explicit event handlers to make them accessible to assistive technologies.

Demo:

With onMouseUp event
With onKeyDown event


Best practices:

  • Use onkeyup instead of onmouseup
  • Use onkeydown instead of onmousedown
  • Use onclick instead of onkeypress

Sample code (taken from Keyboard event keys)

Resources: