Jump to content
AARRGGHHH

Does an HTML5 Control Have Focus?

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! 

Share this post


Link to post
Share on other sites

Thank you for the reply.

"return value" states: 

Return Value: No return value

Thus, I am assuming I cannot use my code to check for focus.   So, how do I check for focus? 

Thank you 

Share this post


Link to post
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.

Share this post


Link to post
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

×