title: Prevent space button from triggering any other button click in jQuery
body: <p>I have an application where I am using the space bar to toggle a function anywhere in the window. However, if any other button or checkbox has focus, then that gets clicked as well.</p>
  
  <p>I tried preventDefault() but that didn't work out as expected. How can I ensure that no other element on the screen gets clicked when I press the spacebar?</p>
  
  <p><em>HTML</em></p>
  
  <pre><code>&lt;button class="buttons" id="playBtn"&gt;PLAY&lt;/button&gt;
  </code></pre>
  
  <p><em>JS</em> (Updated according to <a href="https://stackoverflow.com/questions/940180/using-prevent-default-to-take-over-spacebar">Using prevent default to take over spacebar</a></p>
  
  <pre><code>$(document).keypress(function(event){
      var keycode = (event.keyCode ? event.keyCode : event.which);
  
      if(keycode == '32') {
          if (event.stopPropagation) {
              event.stopPropagation();
              event.preventDefault();
          }
          playBtn_DOM.click();
      } else if (keycode == '97') {
          event.preventDefault();
          prevBtn_DOM.click();
      } else if (keycode == '100') {
          event.preventDefault();
          nextBtn_DOM.click();
      }
  });
  </code></pre>
  
  <p>And with respect to answer <a href="https://stackoverflow.com/questions/940180/using-prevent-default-to-take-over-spacebar">Using prevent default to take over spacebar</a>, that solution didn't work. I have updated the JS code to show that I tried including the solution given there.</p>