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 />')); }); });
Comments
Post a Comment