I was just writing some simple code and I noticed that using document.writeln doesn’t write to a new line, permit me to demonstrate…
// this is my JSON object
var myObject = {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": [{
"Address1": "11 My Street",
"Address2" : "Nice Area",
"Town" : "Nice Town",
"PCode" : "P05T 0DE"
}]
}
document.writeln(myObject.firstName);
document.writeln(myObject.address[0].Address1);
now this outputs the following….
John 11 My Street
It’s all on one line? If I used document.write() I’d expect this? It’s happening in both IE & Firefox. Obviously I could add + "<br/>" or + "\n" but I shouldn’t need to do that?
Am I being stupid?
HTML layout engines fold all whitespace to a single space. Of course you need
<br />or some other mechanism that HTML uses for putting things on separate lines.