I use a ckeditor in which I want to insert a non-editable placeholder. According to the docs you can set an attribute (contenteditable="false") to the desired element to make it non-editable.
In Firefox this is working fine, the attribute is attached on the span but in Chrome the attribute is skipped.
I have a testcase with the following code:
HTML
<textarea id="testeditor"><p>testeditor content</p></textarea>
<button id="addPlaceholder">add placeholder</button>
Javascript
$(function() {
$('#testeditor').ckeditor();
$('#addPlaceholder').click(function() {
var editor = $('#testeditor').ckeditorGet();
editor.insertHtml('<span class="placeholder" contenteditable="false">placeholder</span>');
});
});
EDIT
I made another test to check if the contenteditable attributes is attached when inserting an element to the DOM. This works fine in Chrome.
Javascript
$('body').append('<span contenteditable="false">placeholder</span>');
I found the answer when I googled for an alternative for the
insertHtmlmethod. It seems that you can use the methodinsertElementalso. So I tried and that doesn’t skip thecontenteditableattribute.New code: