Using: focus pseudo class in li or other element than a, input, button, etc.

Is it possible to select an element that is focused, for example: focus or input: focus, but on another element, such as div, li, span or something else?

If this is not possible, how can it be replaced with a tag? I am trying to change the height of the li element when it is focused, tried with a, but the height will not change.


Information requested:

"Can you also explain how you focus on LI?"

Via the css li:focus selector. See https://jsfiddle.net/s4nji/Rjqy5/ .

+7
source share
2 answers

It's simple: just add the tabindex attribute to elements that usually don't get focus.

+6
source

You cannot focus list items. Without even using a script. I tried to do $("li:first").focus() but does nothing. CSS does not set as if it were focused. It just means that you cannot focus list items or that :focus pseudo-classes do not work with list items.

Place anchors inside list items

 <ul> <li><a href="#">...</a></li> <li><a href="#">...</a></li> <li><a href="#">...</a></li> ... </ul> 

This will apparently focus your list item, but will actually focus the anchor labels.

+6
source

All Articles