Ryan,

I'm building in a few keypress events into a site and I'm having
> trouble keeping them from triggering when a text field has focus. For
> some reason this only happens on the second if statement. The first
> one does fine. What am I missing?
>
> The code:
>
> $('*:not(:input)').keypress(function(e){
>
>    if(e.keyCode == some number) {
>         //some function
>    } else if (e.keyCode == some number) {
>        //another function
>    }
>
> });
>

Try:

$(document).keypress(function (e){
   // cancel if in an input field
   if( $(e.target).is(":input") ) return;

   if(e.keyCode == some number) {
        //some function
   } else if (e.keyCode == some number) {
       //another function
   }

});

-Dan

Reply via email to