0

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?

Andrew
  • 4,145
  • 2
  • 37
  • 42

1 Answers1

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