Make an h2 tag unremovable in a contenteditable section
is it possible to make a section within a contenteditable element permanent, so that a user cannot remove it?
I have an h2 tag in a contentEditable div. I don't want the user to edit the h2 tag, so I set contentEditable=false, but the user can still select and remove it, which I want to disallow.
So, for ex:
<div contentEdit开发者_JAVA百科able="true">
<h2 contentEditable="false">My h2 tag</h2>
This is a div you can edit. But you can't edit or remove the h2 tag.
</div>
Nope, sorry, it's all-or-nothin'.
A work-around would be to grab the H2 tag and reinsert it after the edit is complete, using JavaScript.
Why not use position:absolute
to move it above the div (maybe using a proper z-index
) without being inside it (in the source)?
Remember to add some padding to your div in the space allocated for your h2.
精彩评论