a11yClick
a11yClick is a tiny script which allows easy handling of keyboard click events on non semantic button elements. This is a fork from the blog post entitled "Ridiculously easy trick for keyboard accessibility" by Karl Groves. It's also my first attempt at creating a Bower package.
The script weighs in at 20 bytes gzipped and has no dependencies.
Installation
Install with Bower:
bower install --save a11yclick
Add a <script>
tag at the bottom of the page, before your application logic.
<script src="a11yclick.js"></script>
<script src="app.js"></script>
Usage
Wrap the event logic with a conditional statement, checking the return value of the a11yclick()
function. Make sure to pass in the event object.
$('#fake-button').on('click keydown', function(event) {
if (a11yClick(event)) {
// Event logic
}
});
Browser support
- Google Chrome (latest)
- Opera (latest)
- Firefox 4+
- Safari 5+
- Internet Explorer 7+