Hi What im trying to do is that when the esc key is pressed on the text input field (id = txtSearch), some code will run. this is my code:
$(document).ready(function() {
$('#txtSearch').bind('keyup', function(e) {
var characterCode; // literal character code will be stored in this variable
if (e && e.which) { //if which property of event object is supported (NN4)
e = e;
characterCode = e.which;
}
else {
characterCode = e.keyCode;
}
if (characterCode == 27) //if esc key
{
//do stuff
}
});
}
It doesnt work for me. however, if i would change that line:
$('#txtSearch').bind('keyup', function(e) {
with:
$(document).bind('keyup', function(e) {
everything works. but i dont want to bind the keyup with esc to the whole document... any suggestions on how i can bind the the keyup only with the specific text search element? (or its containing div or something) Thanks!