Reputation: 15
I dont know why I cannot make a line break in my javascript. Here is the code:
document.write('It\'s ' + n + ',\n'+'SORRY, WE \'RE CLOSED');
Thanks,
Upvotes: 1
Views: 123
Reputation: 82976
Works for me.
<span style="white-space:pre">
<script>
var n = 10;
document.write('It\'s ' + n + ',\n'+'SORRY, WE\'RE CLOSED');
</script>
</span>
Upvotes: 0
Reputation: 1209
That function will output HTML, so create line breaks by adding <br />
, not \n
.
document.write('It\'s ' + n + ',<br />SORRY, WE \'RE CLOSED');
However, you shouldn't really be using document.write()
:
Why is document.write considered a "bad practice"?
A better option is document.body.innerHTML
or document.createElement()
.
https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
https://developer.mozilla.org/en-US/docs/Web/API/Document
Upvotes: 2