javascript - Prevent keyup event from firing when input box selected -
i have event want fire whenever r or space pressed, exception of when in input field.
specifically, i'm worried <input id='nameinput' type='text'>
dynamically create when click in div , remove onchange
/onblur
. that's why tried checking if( !$('#nameinput') )
, $('#nameinput')
jquery object, boolean value true
(and hence !$('#nameinput') == false
).
$(window).bind('keyup', function(e) { var code = (e.keycode ? e.keycode : e.which); if(code == 32 || code == 82){ if( !$('#nameinput') ){ roll(); } } } );
i have solution utilizes global boolean variable getting set in onfocus of input field, i'd solution doesn't require global variable if it's possible.
is there way determine element has focus?
you can use document.activeelement
know wich element has focus.
if (!$(document.activeelement).is('input, textarea')) { roll(); }
you make use of :focus
selector.
if (!$(':focus').is('input, textarea')) { roll(); }
Comments
Post a Comment