Hide or Close Div Using Escape Key JavaScript | jQuery | AngularJS

Esc key on our keyboard can be useful even in Web pages and applications. We can use Esc key to close dialogue boxes or any custom popup modals. Here we will discuss even handling on ESC key press in which we can fire any event we want.

Let’s handle ESC key press events in Javascript, jQuery, and AngularJS.



In Javascript, we will bind the OnKeyUp event on the window object. In that even we will add a condition if KeyCode is 27 which is of ESC key press, In that event, we will hide the element having an ID


In jQuery, we will use the KeyDown event to bind on the document object.

In AngularJS we need to add a directive which will bind a keyDown event to the body tag


Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Asim Recent comment authors
newest oldest most voted
Notify of


Thanks bro, It works