Viller
Viller

Reputation: 540

How to strip away markup and paste only plain text into content editable field?

Here is playground: http://jsfiddle.net/n6W27/1/

try to Ctrl+A Ctrl+C Ctrl+V and see that contenteditable node was duplicated(at least for me in firefox). The original question is how could I force only plain-text input into contenteditable block? And the derived question is "Why the !@#$ node duplicated next to original one?"

Edit1: There is only one block in this demo, so I put caret inside editable block and then select all, copy, and paste

Edit2: result screenshot enter image description here

Upvotes: 1

Views: 818

Answers (1)

Šime Vidas
Šime Vidas

Reputation: 185933

If you can, change the element type to DIV. That will clear your issue.

<div class="edit" contenteditable>ABC</div>

If you don't want your field to be block-level, set the display property to "inline-block":

.edit {
    display: inline-block;
}

Live demo: http://jsfiddle.net/n6W27/2/

Upvotes: 2

Related Questions