[Solved] – JavaScript – How can we detect escape key press with pure JS or jQuery?

How can we detect escape key press with pure JS or jQuery?

Asked on October 18, 2018 in Javascript.
Add Comment


  • 1 Answer(s)

       The keyup event occurs when a keyboard key is released.The keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs.
    $(document).keyup(function(e)

    {
    if (e.keyCode == 27) { // escape key maps to keycode 27
    // <DO YOUR WORK HERE>
    }
    });

         Trigger the keyup event for the selected elements.Attach a function to the keyup event.keyup method is defined with a method and a function over it and the letter e and with keycode of the value 27 if the keycode = 27 it is the escape key value and is says that do your work.

    Answered on October 18, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.