Tag <pre>

Com edição e retorno do valor

by NunoMira

HTML

<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<pre id="notes" contenteditable="true">Some

test


Txt

</pre>

JavaScript

// Works fine here
console.log($('#notes').text());

// add some text with new lines, then "blur" the text and you can see the issue happening in the log -- new lines not preserved
$('#notes').on('keydown', function (e) {

			if (e.keyCode === 13) {
          document.execCommand('insertHTML', false, '<br>');
          return false; 
    	}
    
});
$('#notes').on('blur', function (e) {
	   console.log($('#notes').html());
});