0

Right, so I'm having some issues with focusing on elements on mobile browsers. Desktop works fine. I've tried click and focus but neither are working so I'm thinking it's maybe something to do with the way I'm identifying it. I know it's a little convoluted and messy but if there's a way to emulate a tab key press this would also work.

Effectively I have 5 inputs and when a single key press is detected in one, I want to move the user to the next one. The way the html is structured though means they are not siblings. I had them as siblings before and choosing nextSibling was working.

Any help appreciated. TIA

 {
            x = document.activeElement.id
            setTimeout(function () {
                document.getElementById("input" + (parseInt(x.toString().charAt(x.toString().length - 1)) + 1).toString()).focus()
                document.getElementById("input" + (parseInt(x.toString().charAt(x.toString().length - 1)) + 1).toString()).click()
            }, 10);

     }
StuP
  • 45
  • 1
  • 6
  • 1
    Touchscreens do not support focus – B Kalra Jun 10 '22 at 09:31
  • 1
    As for simulating keypress events, I recommend [the answer to this question](https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically). For simulating other events, I highly recommend using this [helper function](https://pastebin.com/m4jCNWk2). As for properly debugging mobile (android) devices, it's possible to [link your device with the chrome debugger on your pc](https://developer.chrome.com/docs/devtools/remote-debugging/). – icecub Jun 10 '22 at 09:34

0 Answers0