anonymous4321
anonymous4321

Reputation: 21

Trying to make a line break with Javascript

Trying to get a line break with javascript but its not working.

document.getElementById('section').textContent = "Hello world<br>" + msg;

I also tried:

document.getElementById('section').textContent = "Hello world" + /n msg;

Doesn't work either.. am i missing something?

Upvotes: 0

Views: 83

Answers (1)

Luke
Luke

Reputation: 1724

At the moment, you're adding literal text, NOT HTML <br> elements. You'll either want to set the innerHTML of the element...

document.getElementById('section').innerHTML = "Hello world<br>";

...or create text and <br> elements and append those to the document.

var text = document.createTextNode("Hello world"),
    break = document.createElement("br"),
    section = document.getElementById("section");
section.appendChild(text);
section.appendChild(section);

Upvotes: 5

Related Questions