Turn off keyboard shortcut in text box

I am using something like this:

jQuery(document).keydown(function(e){ // code } 

To switch photos into a photo album with arrows .. This works great, but! I want to disable in textarea. Because if I comment on a photo and I want to move the cursor with arrows, I switch the photo and lose text :)

How to disable it? Can I catch which element is focused? Thanks you

+6
source share
1 answer

You can check if the target element is a text field.

 jQuery(document).keydown(function(e){ var target = e.target || e.srcElement; if ( target.tagName !== "TEXTAREA" ) { // code } }); 
+6
source

Source: https://habr.com/ru/post/902975/


All Articles