views:

569

answers:

2

I have created a DIV with attribute contenteditable=true and appended children like "span" and "a" with attributes contenteditable=false. Wanted to test if the entire node be deleted with a single backspace and to my surprise Firefox couldnt delete the elements. Also this works as expected in all major desktop browsers except Firefox. Any clues on this or what could be the possible workaround?

Found the exact issue on bugzilla here.

A: 

I answered what seems to be an identical question: http://stackoverflow.com/questions/2177958/how-to-delete-an-html-element-inside-a-div-with-attribute-contenteditable. Does my solution not work for you?

Tim Down
hi Tim, your solution is making the backspace work but it is deleting the entire node(text/html). As in the other example you mentioned the solution, when I tried backspace it deleted the entire text in the span. If I write something next to span, the back space deletes all the text written next to span in one key press and the initial span in next kep press. What I expected is the entire content editable works exactly as if you are deleting the text in a normal textarea except that the html elements (like the contenteditable false span) should be deleted in one back space.
Sharief
This works normally by default in other browsers(IE, Safari, Opera, Chrome) except for firefox. This is very annoying.
Sharief
Also your code doesn't work if I edit the content editable div and add some text before the span and try deleting the span with backspace.
Sharief
+1  A: 

Okay! found the solution... its rather simple than what you would think. I am actually inserting html for links, so using <a> here. The <a> tag has attribute set to contenteditable=false and its not getting deleted with a backspace. So I have created an inner <span> level with contenteditable=true for firefox and that did the trick.

<div contentEditable="true">
   <a href="your/url/path" contentEditable="false">
     <span contentEditable="true">link here</span>
   </a>
</div>

This is required in Firefox only. Other browsers treat this as expected with the span having content contenteditable=false.

Sharief