Skip to content

Instantly share code, notes, and snippets.

@neerajsingh0101
Created January 12, 2010 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neerajsingh0101/275557 to your computer and use it in GitHub Desktop.
Save neerajsingh0101/275557 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$(document.documentElement).keypress(function(event) {
if (event.which == 37) {
$('.slider ul a.current').removeClass('current').parent() // moves up to the li element
.prev() // moves to the adjacent li element
.find('a') // moves down to the link
.addClass('current'); // triggers a click on the previous link
} else if (event.which == 39) {
// go right
$('.slider ul a.current').removeClass('current').parent().next().find('a').addClass('current');
}
});
});
<div class="slider">
<ul>
<li><a class="current" href="#1">1</a></li>
<li><a href="#2">2</a></li>
<li><a href="#3">3</a></li>
<li><a href="#4">4</a></li>
<li><a href="#5">5</a></li>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment