WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: onClick and onKeypress

for

From: Christian Heilmann
Date: Oct 4, 2005 8:00AM


> We're working on a site that needs to be Section 508-compliant. We have a link that has a onclick event on it. (We also provide an alternative for users who do not have JavaScript enabled.) Someone told us we need to add a second, redundant onkeypress event to the onclick event (both would do the same thing), to make it more accessible. Is this correct?

Actually you make it less accessible, as some browsers fire the
onkeypress event when you hit tab, too. Opera also allows the user to
jump from link to link via 'a'.

The cleanest way is to make the link a real link and give it an ID and
then add the onclick event dynamically via JavaScript. That way only
JavaScript enabled users will ever get the other functionality and you
don't have to bother about automatic testing suites telling you you
need to add the onkeypress.

http://domscripting.webstandards.org/?p=17

HTH

Chris

--
Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/