1

I have a textarea which already contains some content (haml code below)

//haml code for textarea
%section.input
  .muse_text
    %textarea{placeholder: "Type your muse here..."}

//Content in textarea
"Share why you are re-musing this
------------------
I am remusing this because I like it!!!!
------------------
xxxx"

How can I use jquery to autofocus the textarea and highlight only the first line of the content i.e. "Share why you are re-musing this (when the page loads up)

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Zhen
  • 12,361
  • 38
  • 122
  • 199

1 Answers1

2

When the page loads, focus the textarea (use .focus) after document.ready, or after the textarea is loaded into the DOM. You can use createTextRange or setSelectionRange (depending on the browser) to create a range of text to select .. this can be done when you focus the textarea. You know the length of the "share why.." text, so it should be pretty easy to count.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405