Travis D
Travis D

Reputation: 121

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 contentEditable="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>

Upvotes: 0

Views: 788

Answers (2)

Knu
Knu

Reputation: 15136

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.

Upvotes: 1

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114377

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.

Upvotes: 1

Related Questions