How to detect escape key press using jQuery

1 Answer

0 votes
<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
  </head>
  <body>
    <div>Press the Esc key</div>
    <script>
      $(document).on('keyup', function(event) {
          if (event.key == "Escape") {
            console.log('Esc key pressed');
          }
        });
    </script>
  </body>
</html>


<!--
run:

"Esc key pressed"

-->

 



answered Jan 28, 2021 by avibootz

Related questions

2 answers 287 views
1 answer 240 views
240 views asked Mar 1, 2021 by avibootz
1 answer 285 views
1 answer 291 views
1 answer 438 views
...