title: Use the same keypress to show a div and hide another, repeatedly, using Javascript
body: <p>Lets call the 2 divs in question div1 and div2.</p>
  
  <p>What I'm trying to do is use the enter key to show div1 and hide div2 (if div2 is currently visible) and vice-versa. Right now I have the code so that pressing enter will show div1 and hide div2, but to go back to having div2 shown and div1 hidden you have to use the shift key. The way it is now works, but I would like it so I only have to press enter each time I want the divs to alternate.</p>
  
  <p>Here is the javascript code</p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
      var keys = [];
      var code = [13];
      var keys1=[];
      var code1 = [16];
      $(document).keydown(function(keyEvent) {
        keys.push(keyEvent.keyCode);
        keys1.push(keyEvent.keyCode);
        if ( keys.length &gt; code.length ) {
          keys.shift();
        }
        if ( keys1.length &gt; code1.length ) {
          keys1.shift();
        }
        if ( keys.toString() == code.toString() ) {
          showAns();
        }
        if ( keys1.toString() == code1.toString() ) {
          hideAns();
        }
  
      });
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>Any idea how to accomplish what I'm asking?</p>