I've been playing around with contenteditable
fields, and have come across an odd behaviour that I cannot figure out.
Check out fiddle for this particular problem.
I have two identical contenteditable
divs. Both of them have the same <span>
child, followed by a single blank character (otherwise carrot issues ensue). The only difference between the two is that the second div has been "prettified", and made more readable by indenting the <span>
on a new line.
<div style="margin-bottom: 15px;" contenteditable="true"><span class="lead" contenteditable="false">Something something</span>​</div>
<div contenteditable="true">
<span class="lead" contenteditable="false">Something something</span>​
</div>
Try this in both of the divs...
- Place the carrot to the right-end of the content (i.e. after the blank character)
- Then hit backspace a couple times
You'll notice that in the top (first) contenteditable
div, you can delete the <span>
element, as though it were one giant character. You should also notice that that in the second div, no amount of backspacing will ever clear it out. At least not in Safari.
So what gives!? I thought HTML was whitespace independent - why the difference in behaviour of the two?
Viewing the source, they have slightly different markup...
... but it still behooves me as to why there would be any difference.
I would like it to be deletable, and so the solution is obviously just to use the former version, but it is still curious as to why this issue exists at all.
Also! If you happen to be a contenteditable
guru, I've been fighting with another issue over here. Any help on that one is welcome!