Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

How do i add line breaks to Javascript variables that are displayed in a <div> ?

Hello,

I'm trying to add line breaks, currently using '\n', to make each variable i display in a <div> appear on a new line. At present my code looks like the attached.

The line breaks do not occur - what am i doing wrong?


Many thanks
<div id="infolinks">' + flag_folder.flag + '<b>At the time i visited...</b>\n' + '<b>Language: </b>' + language + '\n <b>Currency: </b>' + currency + '\n' + '<b>Exchange Rate: </b>' + exchange + '\n' + '<b>Plug Type: </b>' + plugtype + '\n' + '<b>Religion: </b>' + religion + '\n' + '<b>Head of State: </b>' + headofstate + '\n' + '<b>Population: </b>' + pop + '\n' + '<b>Per Capita Income: </b>' + pci + '\n' + '<b>National Dish: </b>' + food + '\n' + '<b>National Day: <\b>' + nday + '\n' +'</div><div id="infofooter">I was here on the ' + date + '</div>

Open in new window

0
Daniish
Asked:
Daniish
  • 2
1 Solution
 
hieloCommented:
intead of \n you need to use the html break tag:
<br />

Open in new window

0
 
MMDeveloperCommented:
the \n should only put a line break in the code, not in the display... you'd need to replace them with <br /> to line-break the HTML display
0
 
hieloCommented:
try:
'<div id="infolinks">' + flag_folder.flag + '<b>At the time i visited...</b><br />' + '<b>Language: </b>' + language + '<br /> <b>Currency: </b>' + currency + '<br />' + '<b>Exchange Rate: </b>' + exchange + '<br />' + '<b>Plug Type: </b>' + plugtype + '<br />' + '<b>Religion: </b>' + religion + '<br />' + '<b>Head of State: </b>' + headofstate + '<br />' + '<b>Population: </b>' + pop + '<br />' + '<b>Per Capita Income: </b>' + pci + '<br />' + '<b>National Dish: </b>' + food + '<br />' + '<b>National Day: <\b>' + nday + '<br />' +'</div><div id="infofooter">I was here on the ' + date + '</div>'

Open in new window

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now