Here is example http://jsfiddle.net/omuL8doa/3/
If I press Enter, jquery inserts <br/>
in current place. This is ok.
But after Enter I (cursor) goes to the end of the text. But I need that cursor remains in 'curent' place (the same behavior if I pres enter in Word or Notepad. I mean, press Enter, goes one line below and remains there.
What need to modify to the code?
Here is the code
$('textarea').keydown(function(ev){
if(ev.keyCode == 13){
var caretPos = document.getElementById("main_text").selectionStart;
var textAreaTxt = jQuery("#main_text").val();
var txtToAdd = "<br/>";
jQuery("#main_text").val(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos) );
}
});
` with `\n`. – Craig Lafferty Aug 11 '14 at 19:13