html - jQuery Passing Carriage Return -


i've been working on project far, couldn't figure out how proceed: have textarea user should put input , input should print directly span make happen, when user input carriage return (enter), span text shows space (not carriage return).

i've made (compact) fiddle show how it's @ moment. hope can me.

https://jsfiddle.net/fqnngd44/

$(document).ready(function() {    $('#input').keyup(function() {       $('#text').text($(this).val());    }); }); 

(in other words: need textarea print carriage return (instead of space) when enter key pressed.)

the issue because html converts group of whitespace characters (space, tab, carriage return, etc) single space. around can replace new line in textarea <br />. note you'll need use html() instea of text() display value, otherwise html encoded. try this:

$(document).ready(function() {     $('#input').keyup(function() {         $('#text').html($(this).val().replace(/\r?\n/g, '<br />'));     }); }); 

working example


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -