Text and one-line content with clear text
1 answer
You can disable the Enterkey for an element contentEditable
using JavaScript. Here is the jQuery version:
$('[contenteditable]').keypress(function (e) {
if (e.keyCode == 10 || e.keyCode == 13) {
e.preventDefault();
// Submit the form, etc.
}
})
.on('paste keyup', function () {
var _this = this;
setTimeout(function () {
// remove the markups
$(_this).html($(_this).text());
}, 0);
});
[contenteditable] * {
display: none; /* hide all descendants */
}
[contenteditable] {
display: inline-block;
width: 200px;
overflow: hidden;
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div contenteditable>
blah blah blah...
</div>
+5
source to share