Jump to content

Does an HTML5 Control Have Focus?


AARRGGHHH

Recommended Posts

I'm having a problem determining if a given control has focus.  It seems to me that:

if (form.password.focus() == true) ...

should tell me if the form's password control has focus.  But, it's returning "false" even while I'm typing into the control.  

So, what is the correct way to determine whether a control has focus? 

Thank you! 

Link to comment
Share on other sites

The same you would for onclick, but for onfocus, when on focus set variable to true from false and if you want to attach it to that specific input use custom data- attribute and set the value to that.

Note, you will have to change it back to false, using onblur event.

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...