Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there any method to check if an element is being focused?

Status
Not open for further replies.

unigodx

Programmer
Jan 1, 2009
8
Sorry to ask a very simple question. I do not know a keyword to search.

I have a drop-down list. I want to use if-statement to check whether this list is being focused. Is there any method to check if an element is being focused?

I guess that it will be named like...

element.onFocus()
or
element.onFocusNow()
or something alike.


I will use it like this..

if( myDropDownList.isOnFocusedNow() ){
...//do something
}

Thank you very much.
 
You can use onfocus and onblur to detect an element receiving or losing focus respectively.

You can set these on the element itself:

Code:
<input onfocus="someFunc()" onblur="someOtherFunc()" />

or attaching via script:

Code:
pointerToEl.onfocus = someFunc;

pointerToEl.onblur = someOtherFunc;

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thank you again BillyRayPreachersSon.
Your answers do help me a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top