I would like to ask is there something in CSS that features the function as
document.onkeypress = returnKey;
in javascript? Or other keyboard actions listener in CSS?
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.
No there is not, CSS is static styling.
There are pseudo-classes for certain actions such as
:hover,:link,:activeand:focusetc, but these are element specific.Your best bet would be to assign keydown handlers, and provide a separate class with your styles, thus mixing JavaScript and CSS to get the effect you desire. In the handler, you can apply the class to the element you desire.
A simple (and rough) jQuery example to emulate something like a
:keydownpseudo-class onbodywould be something like this:.. with a corresponding class like this: