Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make a span within a contenteditable div uneditable

I have a contenteditable div, which contains several spans with class dontEdit . Is there a way I can make the spans undeditable, while the rest of the div stays editable.

<div contenteditable=true>
    editable1 <span class="dontEdit">uneditable1</span> editable2
</div>

Please see the fiddle here : http://jsfiddle.net/LZpag/

like image 414
Amarsh Avatar asked Sep 25 '13 07:09

Amarsh


1 Answers

Add contenteditable="false" to each <span> element. If you need to do it dynamically, you can use the contentEditable property in JavaScript. Note that the following won't work in IE <= 8 because those browsers do not support document.getElementsByClassName(), but that's easily worked around if necessary:

var spans = document.getElementsByClassName("dontEdit");
for (var i = 0, len = spans.length; i < len; ++i) {
    spans[i].contentEditable = "false";
}
like image 167
Tim Down Avatar answered Nov 15 '22 12:11

Tim Down