How can I make a line break in a proper way in Javascript?
I was going through the w3schools site for a solution and they came up with this:
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = "Hello \ Dolly."; </script> I tried this code in their Tryit Editor v2.1 provided in their site but this code doesn't work properly there. In the output, everything's ok, except there is actually no line break between the strings 'Hello' and 'Dolly'.
I've also checked this code in my Netbeans 8.0.1 ide and encountered the exact same problem here as well.
I have no idea where the problem is. Or is this not the right way to make a line break? If so, what is the right way to make a line break? Is there a better approach? Please help.
My browser is Mozilla Firefox ver. 32.0.3
Edit - 1:
Thanks a lot to users @ahmadalbayati, @webeno and @TheProvost for providing me the solution. It has been fixed. However, I'd like to add that, apart from their solution, the following code:
<script> document.write("Hello <br/> Dolly."); </script> gives me the exact same output as well. The same, just instead of manipulating a specific html element, it's writing something to the whole html.
document.getElementById("demo").innerHTML = "Hello <br/> Dolly.";