2

Possible Duplicate:
how can i get cursor position in a textarea?

I want some basic but common operations on textarea with javascript, such as

  • get the cursor position
  • set the cursor position
  • insert some text to the cursor position
  • select all text in textarea
  • select a range of text
  • insert some text to the cursor position, and select it immediately.

I hope it working cross-browers.

Is there such javascript library?

Community
  • 1
  • 1
Freewind
  • 193,756
  • 157
  • 432
  • 708
  • 3
    Have a look at this http://stackoverflow.com/questions/1891444/how-can-i-get-cursor-position-in-a-textarea/1909997#1909997 – Craig May 13 '11 at 17:00
  • Or: http://code.google.com/p/rangy/. – pimvdb May 13 '11 at 19:29
  • @pimvdb, `rangy` is powerful, but it's too big(39K after compressed). – Freewind May 14 '11 at 01:55
  • I think this is not exactly the same as that one. I don't only want to get the cursor, but also replace, reselect some text. That question doesn't help me. – Freewind May 15 '11 at 11:05

1 Answers1

2

There's a jQuery plug-in I've written that does all of this. There's a standalone version too but it needs a little bit of tidying. If you'd prefer no jQuery then it would give me a reason to sort it out and release it.

Tim Down
  • 318,141
  • 75
  • 454
  • 536