javascript - changing the background on keydown event -


i trying change background color of ul when keydown event occurs.when press down arrow corresponding ul should change background color.

here code

 <div class=".container">  <ul>  <li>one</li>  </ul>  <ul>  <li>two</li>  </ul>   <ul>  <li>three</li>  </ul>       <div>   var chosen = "";  $(document).keydown(function(e){ // 38-up, 40-down  if (e.keycode == 40) {   if(chosen === "") {  chosen = 0;  } else if((chosen+1) < $('.container ul').length) {  chosen++;   }  $('.container ul').removeclass('selected');  $('.container ul:eq('+chosen+')').addclass('selected');  return false;  }  if (e.keycode == 38) {   if(chosen === "") {  chosen = 0;  } else if(chosen > 0) {  chosen--;              }  $('.container ul').removeclass('selected');  $('.container ul:eq('+chosen+')').addclass('selected');  return false;  }   });   .selected  {  background:red;  } 

here fiddle http://jsfiddle.net/lp6y6/

change this:

<div class=".container"> 

to this:

<div class="container"> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -