[jQuery] Troubles with binding to an element by id

[jQuery] Troubles with binding to an element by id


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; //character code is
contained in NN4's which property
}
else {
characterCode = e.keyCode; //character code is
contained in IE's keyCode property
}
if (characterCode == 27) //if generated character
code is equal to ascii 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?
Thanks!