1

So I have a contenteditable button in my webpage I declare like so:

<button id="test" contentEditable="true">This <img src="image..png" /> is a button, click me!</button>

I move the caret around, and I want to find its final location. I tried both:

  • window.getSelection().focusOffset.toString()
  • document.getElementById('test').selectionStart.toString()";

but neither of them seems to work :( Any pointers?

Freakishly
  • 1,533
  • 5
  • 32
  • 61

1 Answers1

0

Update

Unfortunately the code from the links below seems to work only with Firefox and not with Chrome (for a button, divs work just fine)


Take a look at these:

Here's a quick and dirty fiddle - it isn't perfect but it might help you get started. I've used code from the blog post at the second link above.

Community
  • 1
  • 1
no.good.at.coding
  • 20,221
  • 2
  • 60
  • 51
  • Hey nogood, I looked at the first example on SO for the caret position, it works for contenteditable div but not button. I saw your code snippet. Did you try executing it? It didn't work for me... – Freakishly Mar 29 '11 at 22:49
  • @Freakishly, I just tried it again, it works fine in FF4 but doesn't work in Chrome. – no.good.at.coding Mar 29 '11 at 22:55