JavaScript 'contenteditable' -- Getting/Setting Caret Position

Posted by OneNerd on Stack Overflow See other posts from Stack Overflow or by OneNerd
Published on 2010-05-16T17:10:01Z Indexed on 2010/05/16 18:30 UTC
Read the original article Hit count: 1125

Filed under:
|

I have read a few posts on positioning the caret, but none seem to answer my particular issue.

  1. I have 2 divs (div1 and div2)
  2. div1 = noneditable div
  3. div2 = contenteditable div
  4. both divs contain exact same contents
  5. when user clicks on div1, it gets hidden, and div2 appears in exact location and user can edit

The problem: I want the caret to appear in exact location on div2 as div1

So, I need some way to READ the location where the user clicks on div1, and then when div2 appears place the cursor/caret in that same location, so a getCaretLocation(in_div_id) and setCaretLocation(in_div_id) set of functions.

Any way to do that?

Thanks -

© Stack Overflow or respective owner

Related posts about contenteditable

Related posts about JavaScript