2

Is there any way to trigger the focus() event on a <textarea> element and put the mouse cursor at the end of the text which is inside the textarea?

thx

itsme
  • 48,972
  • 96
  • 224
  • 345

1 Answers1

3

Was going to close as duplicate, but the other one doesn't cover how to trigger the focus.

See: Use JavaScript to place cursor at end of text in text input element for how to put the mouse cursor at the end

And to trigger the focus, you just need $('#foo').focus() or $('#foo').trigger('focus')

Community
  • 1
  • 1
Jamie Wong
  • 18,104
  • 8
  • 63
  • 81