Hi, my name is
Lee Harris and
I'm a Freelance Web Designer

How to detect an escape key being pressed using jQuery

21.Apr.2019 |

A quick snipped of code that can be used attach a function to the escape key. Great for adding or removing a class. I always attach this to close a popup, for example.

jQuery(document).on( 'keydown', function ( e ) {
	if ( e.keyCode === 27 ) { // ESC
	    // Do Something...
	}
});

,

  • html5
  • css3
  • sass
  • php
  • WordPress
  • WooCommerce