JSFiddle - React, Tailwind, and code Playground

by Bhupesh Kushwaha

HTML

<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<div id='aa' contenteditable='true'></div>

CSS

div{background-color:red; }

JavaScript

$('#aa').keydown(function(e) {
var datasts=$("#aa").html();
datasts=datasts.substr(datasts.length - 1);
if (e.keyCode === 13) {
document.execCommand('insertHTML', false, 'enter');
return false;
}
});
document.getElementById("aa").addEventListener("input", function() {
$("#aa").html($("#aa").children().not("br, img").remove());
}, false);