title: Execute event listener function only once without jquery
body: <p>I made a piece of code that moves an element vertically in front of 6 items with arrow up and down. When enter is pressed i will load a set of images with that item. The code works fine but after enter is hit, this piece of code needs to stop, so i can do other things with my arrow keys and enter. Now it just keeps going after enter is hit. I tried it with a var check as you can see but i cant seem to change the variable from within the switch. Someone have an idea how to make this work?</p>
  
  <pre><code>var enterPushed = false;
  
  if(!enterPushed){   
          document.addEventListener('keydown', function(event){
      if(event.keyCode == 38){
          console.log("up");
          if(margTop &gt; 122){
              margTop = margTop - 60;
              marginTop();
              i = i - 1;
              bliep.play();
          }
      }
      if(event.keyCode == 40){
          console.log("down");
          if(margTop &lt; 422){
              margTop = margTop + 60;
              marginTop();
              i = i + 1;
              bliep.play();   
          }
      }
      if(event.keyCode == 13){
          switch(i){
              case 1:
                  enterPushed = true;
                  startup(1);         
              break;
              case 2:
                  enterPushed = true;
                  startup(2);             
              break;
              case 3:
                  enterPushed = true;
                  startup(3);         
              break;
              case 4:
                  enterPushed = true;
                  startup(4);         
              break;
              case 5:
                  enterPushed = true;
                  startup(5);             
              break;
              case 6:
                  enterPushed = true;
                  startup(6);         
              break;
          }
      }
  });
  }
  </code></pre>