1

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

George Brighton
  • 5,131
  • 9
  • 27
  • 36
Wazza
  • 11
  • 2

2 Answers2

2

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.
            }
        });
xandy
  • 27,357
  • 8
  • 59
  • 64
  • How can I control the cursor, not to go back to the beginning of the line after modifing the $("#content").text() or .html()? (the .val() does not work for me). – Johan Jul 27 '10 at 13:34
0

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

Community
  • 1
  • 1
NeilC
  • 1,380
  • 1
  • 17
  • 36