Reputation: 11
I have a content editable area and I'm trying to disable enter/return and shift enter from creating a new paragraph, I have this working with the script below but it disables the buttons all together, what I wish to do is have return just place a line break rather then go to a new paragraph.
$("#content").keypress(function(e) {
return e.which != 13;
});
All help appreciated!
Cheers,
Wazza
Upvotes: 1
Views: 2474
Reputation: 1390
See this answer on how to place the caret after the inserted node, plus on how to add a node : Set caret position right after the inserted element in a contentEditable div
Upvotes: 0
Reputation: 27411
Try something like this:
$("#content").keypress(function(e) {
if (e.which == 13) {
e.preventDefault(); // I think this is the keyword you look for?
$("#content").val($("#content").val() + "<br/>"); // Handler for new p or line break etc.
}
});
Upvotes: 2