Focus on textInput after click on button.

Hi ! :wave:

What's the best way to get focus on text input ? I tried with javascript but nothing happened :

  observeEvent(input$ends_wrds, {
      updateTextInput(session, "user_seq",
                      value = paste(wrd_begin,input$ends_wrds))
      HTML("<script> const input = document.getElementById('user_seq');
            const end = input.value.length;
            input.setSelectionRange(end, end);
                        input.focus(); </script>")
  })

The idea is to focus on a text input after an update of this input.
Regards.

Solution :

I write a file named focus.js and this file was loaded in ui part with tags$script(src = "focus.js"),.

In this focus.js :

document.getElementById("user_seq").onchange = function() {doThing()};

function doThing(){
  document.getElementById("user_seq").focus()
}

That was easy.