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.
- Bind keyup event with textbox/textboxes.
- Check the keycode.
- 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.