i have a input tag which is non editable, but some times i need to remove the text inside that by pressing delete or back space keys. how can i do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would advise against using the backspace key, since that is usually associated with the browser’s back button.
Here is how to solve your problem with .keyup() and only the delete key (jQuery normalizes
e.which):jsFiddle example
Quirksmode has a useful page on detecting keystrokes..
The above captures key presses anywhere on the page by attaching the
.keyup()to thedocument. You must do this, since theinputis not editable.You could also use
keydown(), but it’s best not to usekeypress().