views:

1147

answers:

1

Hi Guys,

I have a content editable area and im 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 buttoms 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

+2  A: 

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
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