Created
January 11, 2018 21:06
-
-
Save nateplusplus/6dcbf630620b07766eb06ab81d7d3d03 to your computer and use it in GitHub Desktop.
Accessible jQuery events - it's always more than a simple "click"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#elementId').on('click keydown', function(e) { | |
// Respond to mouse click or enter | |
if (e.type == 'click' || (e.type == 'keydown' && e.keyCode == 13)) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
// Do stuff... | |
} | |
// Respond to down arrow | |
if (e.type == 'keydown' && e.keyCode == 40) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
// Do stuff... | |
} | |
// Respond to up arrow | |
if (e.type == 'keydown' && e.keyCode == 38) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
// Do stuff... | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment