2

I am trying to set a contenteditable span so that it will on the onkeyup event refill the span with formatted text.

However, when I try this the cursor disappears and I can't type anymore. This is because the formatting program, instead of modifying the text already in the span, erases it all and then writes the formatted text in its place.

It is important (I think it is) to note that the element does not appear to be losing focus. Also, because I would like for this project to remain fairly "secret" until it's release, I would rather not give away the source code right now.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
chrismamo1
  • 917
  • 1
  • 7
  • 15
  • How can i place the caret/cursor/insertion point in a conenteditable span using javascript in much the same way that you could do it with a textarea – chrismamo1 Nov 06 '11 at 18:17
  • Here's my answer to a similar question: http://stackoverflow.com/questions/6240139/highlight-text-range-using-javascript/6242538#6242538 – Tim Down Nov 07 '11 at 10:47

1 Answers1

1

This is probably due to you using the innerHTML to set the formatted text.

Instead use childNodes collection to access the content and replace textNodes with formatted html element. This avoids setting innerHTML and avoids loosing focus.

Jeemusu
  • 10,415
  • 3
  • 42
  • 64