1

I want an output like this:

   1st line-  " Your total purchase cost is Rs.980"
   2nd line-            Thank You!

my code snippet:

document.getElementById("result").innerHTML = 'Your total purchase cost is Rs' +result;
<div id = "result"> </div>

I tried adding:

document.getElementById("result").innerHTML = 'Your total purchase cost is Rs' +result <br> 'Thank You!';

and adding a new line with \n.

Please help me understand this.

Rick
  • 1,177
  • 1
  • 19
  • 27
aruncj
  • 23
  • 5
  • How is this a duplicate of how to efficiently concatenate multiple strings in javascript? The OP asked how to add new lines in a javascript string so that it renders in the HTML as an actual new line. – Antoniu Livadariu Nov 28 '17 at 09:49

1 Answers1

2

If you're injection HTML into some div, new lines should be also done using HTML - <br />.

document.getElementById("result").innerHTML =
  'Your total purchase cost is Rs' + result + '<br />Thank You!';
hsz
  • 148,279
  • 62
  • 259
  • 315