- “\n” character.
- “</br>” tag.
In this example, the “\n” character is used to break the string value twice by placing line breaks:
In the above code snippet:
- Firstly, create a variable and assign the stated string value.
- In the string value, the allocated “\n” characters will place line breaks in the string value.
- Finally, display the resultant string value with two-line breaks on the console.
In the above output, it can be seen that the specified string value has been split into new lines.
The “</br>” tag is used to place a line break in the HTML code. This tag can also be utilized to break the string value into two or more two lines.
Let’s go through the below code lines:
document.getElementById('myHeading').innerHTML = myText;
According to the given code snippet:
- Firstly, include the “<h3>” tag to accumulate the resultant string value as a heading.
- In the specified string value, the “</br>” tag indicates that the string content will be displayed in the new line after the placed tag./li>
- Lastly, access the included heading by its “id” using the “getElementById()” method and append the resultant string value in the form of a heading via the “innerHTML” property.
In this output, it is evident that the resultant string value with the line breaks is displayed in the form of a heading.