Currently under Firefox when I press return in a contenteditable
paragraph it inserts a br
tag creates a new paragraph tag and then puts a br
tag inside that new paragraph. I would like to modify the behavior such that
I would find it most helpful if anyone out there knows how to..
Perhaps someone even knows of a user agent (browser) that already behaves in this way. That is acceptable.
To edit content-editable behavior, I'd do this:
$("#editable").bind("keypress",function(e){
if(e.keyCode==13 && e.shiftKey){ //enter && shift
e.preventDefault(); //Prevent default browser behavior
this.html(this.html+"<br>");
}
});
You can edit what's inside the html
function. PS: I don't remember if jQuery has the shiftKey
and keyCode
on the event object...if anything goes wrong change e
to e.originalEvent
.
To Get carret position: In non-IE:
document.getSelection().anchorOffset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With