i am trying to write rtl and ltr in one sentence in contenteditable div,but the whole sentence screwup.. i have tried to stick the cursor to end while writing but the words mirrored like ybab instead of baby and i cant seprate the words with space
var div = document.getElementById("editor_content");
div.onkeydown = function() {
var sel, range;
if (window.getSelection && document.createRange) {
range = document.createRange();
range.selectNodeContents(div);
range.collapse(true);
sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(div);
range.collapse(true);
range.select();
}
};
please help me
I dont know exactly what you want to do, but i guess you want to type text from left to right and then have it mirrored from right to left....by words...not by letters.
http://jsfiddle.net/rainerpl/asrny8zd/1/