Link to home
Start Free TrialLog in
Avatar of Daniish
DaniishFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of hielo
hielo
Flag of Wallis and Futuna image

intead of \n you need to use the html break tag:
<br />

Open in new window

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
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial