Home>

a is placed at the beginning of the input

$('button').on('click', function() {
  $('input').focus();
})
<input type="text" value="texttext text"><button class="edit">put focus at the end of the text</button><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

And why did you decide that he should be put there?

Igor2022-02-12 22:18:14

@Igor, they just want to. and it seems logical. or not?

nastya2022-02-12 22:18:14

no, it's not logical. Otherwise, when navigating through page elements from the keyboard, this would have been done initially. But, as we can see, when an input receives focus without the help of a mouse, its entire content is selected -the developers did this for a reason.

Инквизитор2022-02-12 22:18:14
  • Answer # 1

    As an option

    $('button').on('click', function() {
      let inpValue= $('input').val();
      $('input').focus().val('').val(inpValue);;
    })
    <input type="text" value="texttext text"><button class="edit">put focus at the end of the text</button><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>