Jump to content

Detect input/textarea active


wongadob

Recommended Posts

Is there any way in jQuery or Javascript that you can detect if the current focused/activce element is a textarea or input area. The reason for this is I need to use hotkeys but they will be standard keys (i.e. not control+key) so I need to do a key listener and then make it ignore the keypress and fall through if the user is inputting text. I can do this by testing the ID for the ID's of all mt inputs/textareas, but that seems to be a tad long winded. Be great if there was something like $(document).currentactiveID But can't seem to find anything As always any help much appreciated

Link to comment
Share on other sites

$("input[type='text'], textarea").focus( function(){alert("you have focused on a textarea or input of type text")});

To target all inputs remove '[type=text]', to target specific ID or class add to input selector input.myclass, input#myid

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...