jQuery to clear textbox value using ESC key

Yesterday worked on interesting thing. Requirement was to clear the textbox text when escape (Esc) key is pressed within textbox. This was easy and simple.

  1. Bind keyup event with textbox/textboxes.
  2. Check the keycode.
  3. If keyCode is 27 (which is for esc key) then clear the text.
$(document).ready(function() {
    $('input[type="text"]').keyup(function(e){
        if(e.keyCode == 27) {
            $(this).val('');
        }
    });
});?

See result below

See Complete Code

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...