Search code examples
javascripttouchselectors-api

How to detect what element has the focus, on touch devices


To detect what element is fired, when my user clicks on an anchor or submits a form, I use that selector :

'form input[type=submit]:focus,' +
'form button[type=submit]:focus,' +
'form button:not([type]):focus,' +
'a:focus,' +
'form input[type=submit],' +
'form button[type=submit],' +
'form button:not([type])'

But it doesn't work on touch devices, how to solve it please ?


Solution

  • Found the solution: try to get the element by the pseudo-selector :hover, in place of :focus