Context is Chrome 37.0.2062.120 m.
I'm using execCommand to insert html into an editable div. My execCommand call looks like this:
function insertHTML(){
document.execCommand('insertHTML', false, '<span id="myId">hi</span>');
}
When the editable div looks like this:
<div contenteditable="true">
some [insertion point] content
</div>
and I use execCommand to insert html into a contenteditable div, all of the attributes of the HTML are inserted as expected and I end up with this:
<div contenteditable="true">
some <span id="myId">hi</span> content
</div>
When, however, I insert the exact same html into this structure:
<div contenteditable="true">
some content
<div>more [insertion point] content</div>
</div>
The attributes are removed from the span being inserted and it ends up looking like this:
<div contenteditable="true">
some content
<div>more <span style="font-size: 10pt;">hi</span> content</div>
</div>
Is there any way to keep this from happening?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…