How to 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.

 

One thought on “How to Hide or Close Div Using Escape Key JavaScript | jQuery | AngularJS”

Leave a Reply

Your email address will not be published. Required fields are marked *