+ 1
java Script
'\n' is not working although i used it in different ways
6 Antworten
+ 9
Motasem Gozlan
Short answer - Use <br> instead of \n when showing the output in HTML (i.e. when using document.write() or document.innerHTML)
Long answer -
When you write :
document.write("Hello" + '\n\n' + "World");
The HTML source will be -
Hello
World
..and HTML removes the extra spaces (only keeps one space). So it shows only -
Hello World
When you write :
document.write("Hello " + "<br>" + " World");
The source code is -
Hello <br> World
..which HTML shows as
Hello
World
Hope it clears! Feels free to ask if you've any more doubt
+ 7
Please show us your code.
+ 2
As far as I know, variable strings do not work with \n but with <br />, same as document.write&document.writeln
alert and console will execute \n
Look at the provided post, should explain it.👍
https://www.sololearn.com/discuss/1493807/?ref=app
+ 1
thank you nikhil its clear enough
0
alert("Hello Motasem");
document.write("<h1>MGHZ</h1>");
var name = "Motasem";
var welcome = "\nWelcome " + name;
var age = 20;
var adulte = (age < 18)? "\ntoo young" : "\nold enough";
document.write(welcome + '\n');
document.write("\n you are " + adulte + '\n');
0
thank you