Thanks Dan! That looks to be what I was missing. I kept trying focus()
but for some reason it always came back false even if I was in an
input.

Ryan

On Nov 1, 3:31 pm, "Dan Switzer" <[EMAIL PROTECTED]> wrote:
> 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