I want to apply a line break to a dom element programatically.
I have tried to used <br>
, <br/>
and \n
from different answers of solving this problem.
However, none of them work.
Here is an example:
<!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js -->document.getElementById('1').textContent = "\n".repeat(6)
document.getElementById('2').textContent = "<br/>".repeat(6)
<!-- language: lang-css -->
p {
border: 1px solid black;
}
<!-- language: lang-html -->
<h2>Set <code>\n</code></h2>
<p id="1"></p>
<h2>Set <code><br/></code></h2>
<p id="2"></p>
<!-- end snippet -->
The <br>
, <br/>
will appear in the textContent
, but doesn't apply the line break.
The \n
doesn't appear in the textContent
, and also doesn't apply the line break.
Do anyone know how to solve this problem?