The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Keyup not working

  • # December 18, 2012 at 11:37 pm

    I’m a novice when it comes to javascript and am trying to get the escape key to exit site quickly, following the post and using the script. Everything is working except the following code:

    $(document).keyup(function(e) {
    if (e.keyCode == 27) { // escape key

    Any help greatly appreciated.


    # December 18, 2012 at 11:41 pm

    @Cathyk Hi. I’m not that familiar with Javascript either but do you have a link to your site so I can see if the console is throwing an error?

    # December 18, 2012 at 11:51 pm

    I have a testing site at

    # December 20, 2012 at 1:28 am

    @Cathyk : First, if you plan on using jQuery then you need to reference it locally or through a cdn. Add this:

    <script src=""></script>

    I slightly modified your code as well as included an example.

    function getAway() {'','_newtab');

    $(do​cument).keyup(function(e) {
    if (e.which === 27) {

    jsFiddle because CodePen was being a weirdo. I hope this helps.

    # December 20, 2012 at 1:51 pm

    @John: THANK YOU! As I stated, I’m a novice & didn’t have the link for jQuery. Once I placed that in the file, it works!

    Enjoy your holidays!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed