I have a problem with That looks like (on the contentEditable DIV): But after sanitization (removing In Firefox, the And that after sanitization looks the same: Is there any solution to "normalize" this across browsers? I've found this code on Make a This works, but (in SAFARI and CHROME) I have to press two times the "return" key to get a new line... Any idea? Edit: With the code I found ( at the bottom of this question) is working fine except the function that "makes sure a Edit 2: I'm getting this error on the console: Edit 3: Ok, I changed the The problem is now that when I'm inside an Ordered or Unordered List, I need to get a new line without Edit 4: If anyone interested in the solution of the last edit: Avoid createElement function if it's inside a contenteditable
line breaks on SAFARI/CHROME. When I press "return" on a contentEditable
(like Firefox), they create a new Something
Something
SomethingSomething
contenteditable
is:Something
Something
Something
Something
instead of by pressing Enter on a contenteditable$(function(){
$("#editable")
// make sure br is always the lastChild of contenteditable
.live("keyup mouseup", function(){
if (!this.lastChild || this.lastChild.nodeName.toLowerCase() != "br") {
this.appendChild(document.createChild("br"));
}
})
// use br instead of div div
.live("keypress", function(e){
if (e.which == 13) {
if (window.getSelection) {
var selection = window.getSelection(),
range = selection.getRangeAt(0),
br = document.createElement("br");
range.deleteContents();
range.insertNode(br);
range.setStartAfter(br);
range.setEndAfter(br);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
return false;
}
}
});
});
element is always the lastChild... Any idea on how to fix this?Uncaught TypeError: Object #
document.createChild("br");
to document.createElement("br");
and I think I got it working in FF/Safari/Chrome... All return
for new lines...
...