Maria Jane
Maria Jane

Reputation: 2403

adding newline in string concatenation

I have a textarea and I do console.log($("textarea").val()), the result can be

abc

123

And I have an input, i want to concate the value with the value of textarea, like this

input_value

abc

123

I tried <br> but the br will appear which is not I want. How to make newline in concatenation? use \n?

Upvotes: 2

Views: 18598

Answers (2)

Cody Higdem
Cody Higdem

Reputation: 43

You can try something like this:

alert('abe \n' + 123);

\n Seems to do the trick for you.

Further Reading: http://www.w3schools.com/jsref/jsref_regexp_newline.asp

Upvotes: 0

Hulothe
Hulothe

Reputation: 764

Use \n instead of <br>. Like that:

console.log($("input").val() + '\n' + $("textarea").val());

Upvotes: 3

Related Questions