JavaScript document.write newline

 JavaScript document.write can be used to output text strings, and even can output strings containing HTML tags. This article mainly introduces how to use HTML wrap tags to make document.write output text strings with a wrap effect, just like direct Write the content of the article in the HTML page like a newline paragraph.


JavaScript document.write basic syntax

document.write('Write the text you want to present here');


Just write HTML line break tag <br> or paragraph tag <p> directly in the parentheses of document.write. Note that the part containing HML line break tag must be enclosed in quotation marks, either single or double quotation marks Yes, if the quotation marks are omitted, the newline tag will be treated as a variable and make an error.

JavaScript document.write line break example
<script language="javascript">
document.write('This is the first line<br>');
document.write('This is the second line<br>');
document.write('<p>This is The first paragraph</p><p>This is the second paragraph</p>');
</script>
The output of the above example
This is the first line
this is the second line

This is the first paragraph

This is the second paragraph

The HTML <br> line break tag and <p> paragraph tag are used in the example. If you just output one line at a time, you can use the <br> line break tag. If you want to output a paragraph, use the HTML <p> paragraph tag. The difference between the two is that <br> will only change one line at a time, while <p> will change two lines at a time, and each set of <p></p> tags will have a line spacing.

Post a Comment

0 Comments