Is there a CSS or jQuery selector for the element which has received focus via the tab key, like you commonly do with anchor tags and form elements?
Asked
Active
Viewed 1,598 times
1 Answers
2
This should work for you.
if ($(".selector").is( ":focus" ))
{
// Do something
}
If you want to highlight an element on focus use this:
$(".selector").focus(function()
{
$(".selector").css("background-color","#FF99CC");
});
EDIT: @Musa brings up a good point. If it has to be triggered by tab then look at this post: jQuery: How to capture the TAB keypress within a Textbox I know it's for a textbox but it shouldn't be too hard to do.

Community
- 1
- 1

Nate-Wilkins
- 5,364
- 4
- 46
- 61
-
Yea but I like to extend sometimes if people aren't used to a language. – Nate-Wilkins Sep 21 '12 at 20:57
-
sure, it depends on the actual purpose. maybe CSS is enough, maybe Drew needs jQuery – szajmon Sep 21 '12 at 20:59
-
I was really just curious about tab selection, but your answer made me think about what's actually going on there. +1. – Andrew Sep 26 '12 at 19:58
-