Reputation: 9293
I placed cursor just after lorem
and press Enter
By default, pressing enter
, chrome writes here its own span
tags.
$("#test").keydown(function(e) {
if (e.keyCode == 13) {
e.preventDefault();
var a = "<br>\n";
/* here I need something like this:
write - on - cursor - position(a); */
};
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test" contenteditable="true">loremIpsum</div>
Upvotes: 1
Views: 251
Reputation: 43870
Remove this property e.preventDefault();
and the desired behavior will be enabled.
$("#test").keydown(function(e) {
if (e.keyCode == 13) {
/* e.preventDefault(); */
var a = "<br>\n";
};
});
#test {
height: 100px;
width: 75%;
padding:10px;
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test" contenteditable="true">loremIpsum</div>
Upvotes: 1