jquery - Javascript - bind to keys events, except if user is in a text input -


so have page, in user can use directional keys navigate between different items. that, use jquery binder :

$(document.body).bind('keydown', function(event) { // use directional keys 

i want event work @ every time, except if user focused in text input.

so tried filter out event this:

$(document.body).bind('keydown', '*:not(input[type="text"], textarea)', function(event) { 

but unfortunately filter not work, , event fires in every case.

i detect focus (and blur) events on every input in page, , deactivate move event via global boolean, find quite inelegant.

is there way either let input fields "consume" events, or filter event reverse selector tried ?

thanks in advance,

that isn't valid .bind() syntax. events passed .bind() cannot delegated.

you mean use .on():

$(document.body).on('keydown', '*:not(input[type="text"], textarea)', function(event) {  }); 

jsfiddle

if using jquery version prior .on() (which shouldn't be..) can use delegate():

$(document.body).delegate('*:not(input[type="text"], textarea)', 'keydown', function(event){  }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -