increment div's value on keydown
Hi! I would like to increment the value of two divs by one each time a press the left or the right arrow button.
It doesn't work, says
[13:04:50.297] TypeError: this[0].innerHTML is undefined @ http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js:12
- <div class="centered">
- <span id='first'>0</span>
- <span id='second'>0</span>
- </div>
- <script>
- $(document).ready(function(){
- $(document).keydown(function(key) {
- switch(parseInt(key.which,10)) {
-
- case 37: //left arrow
- $('#first').html( parseInt($(this).html()) + 1);
- break;
-
- case 39: //right arrow
- $('#second').html(parseInt($(this).html()) + 1);
- break;
-
- default:
- break;
- }
- });
- });
- </script>