Skip to content
Advertisement

New line string from javascript

I cant do new line from javascript, I tried to do that with n, but nothing.

document.getElementById("text").textContent =  "hhh" + 'n' + "df"; 
<h1 id="text">
  abc
</h1>

Advertisement

Answer

Apparently you are pretty new in javascript. You should use <br> instead. n new line for console outputs. Also you should use innerHTML instead of textContent.

document.getElementById("text").innerHTML =  "hhh" + '<br>' + "df"; 
<h1 id="text">
  abc
</h1>

With textContent

document.getElementById("text").textContent =  "hhh" + '<br>' + "df"; 
<h1 id="text">
  abc
</h1>

Console example:

console.log("abcndef");
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement