David David - 7 days ago 5
Javascript Question

New line is not working in Javascript

New line is not working in Javascript.

I am using new to add two string and second string should be in new line but

\n
is not working.

My code is like

var s1 = "Hello";
var s2 = " My world";

var s3 = s1 +"\n"+ s2


output shuld be like :

Hello

My World

any suggetion. thanks for help

Answer

Use <b></b> to add the bold and <br> for the line break

var s1 = "Hello";
var s2 = "<b>My</b> world";

var s3 = s1 + "<br>" + s2;

document.getElementById("text").innerHTML = s3;
<p id="text"></p>

Comments