Home > Software design >  Replace \n from textarea with "invisible" line break in console
Replace \n from textarea with "invisible" line break in console

Time:05-26

console.log('Hello\nworld'); outputs:

Hello
world

If I write "Hello[ENTER_KEY]world" into a <textarea>, then console.log($('textarea').html()) outputs:

Hello\nworld

How can I convert this so that \n isn't printed but shown as a line break in the console?

CodePudding user response:

Try to use textarea value property as below:

function myFunction(){
console.log(document.getElementById('myTextArea').value);
}
<textarea id="myTextArea" onchange="myFunction()"></textarea>

CodePudding user response:

Try getting value instead of innerHTML

console.log($('textarea').val());
  • Related