title: Pause HTML5 video if it was interacted with using spacebar like youtube?
body: <p>I'm using "vanilla" javascript :) I'm trying to replicate youtube's method of pausing video if spacebar is pressed. I'm able to get video to pause if the event is bound to the window but not the video, here is my code.</p>
  
  <pre><code>window.addEventListener("keyup", function(evt) {
       if (evt.keyCode === 32) {
          if (video.paused) {
            video.play(); 
          }
          else { 
            video.pause(); 
          } 
      }
   });
  </code></pre>
  
  <p>As in the code above, using <strong>window</strong> works, but if i change <strong>window</strong> to <strong>video</strong> it doesn't work anymore even if I've interacted with the video player. Reason of necessity : if user is watching a video and wants to leave a comment, everytime they press the spacebar the video starts and pauses over and over again. So I need it to only pause or start if user has interacted with the video player and not clicked anywhere else, like youtube. Kind thanks.</p>
  
  <p>Edit: Noticed youtube uses Tabindex (never used it before), to make controls focusable, so that has something to do with it? That's only controls though and not the actual screen.</p>