$(document).on("keypress", "input[type!='password'], textarea", function (event) {
alert("this works!");
});
The listener is being attached to the document
, and any keypress events will be checked against input[type!='password']
and textarea
.
If your HTML markup was structured in a way that there was one parent container of input[type!='password']
and textarea
, you could replace $(document)
with $('.parent-container')
to only attach the listener on that element, as opposed to the entire document.
EDIT: Here's an example: http://jsfiddle.net/yz7F5/5/