Approach
I would like to make a div
that would be totally unmodifiable , preferably, inseleccionable and unfocusable even if it is within an element that have the contentEditable
attribute enabled.
Note: I can not choose to put the div outside and position it with absolute position, because I need to position it relative to the upper container.
Attempts
At the moment I have tried with the modern property pointer-events
, but moving the arrows can make fun.
So as a patch I tried to change the text back to its original value programmatically.
var modificadoporcodigo = false;
$('#encabezado').bind("DOMSubtreeModified", function() {
/*console.log(e.which);
if (e.keyCode == 46 || e.keyCode == 46) {
alert('Lo sentimos, los encabezados no se pueden borrar');
}*/
if (modificadoporcodigo) {
modificadoporcodigo = false;
} else {
$('#encabezado').text('Prueba');
modificadoporcodigo = true;
}
});
#encabezado {
color: gray;
position: absolute;
top: 27px;
pointer-events: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="fondoCuerpo" class="col col-md-12">
<div class="Hojas" contentEditable="true">
<div id="encabezado">Prueba</div>
Hola Mundo!
</div>
</div>