0

How do I get a CR/LF when setting textContent? I've tried a couple things (below) but these do not work. The \r\n has no effect, the <br /> is displayed literally.

document.getElementById("lbResult").textContent = "\r\nmyID"
document.getElementById("lbResult").textContent = "<br />myID"
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
  • See [this question](http://stackoverflow.com/questions/9330671/add-linebreak-to-textcontent-or-innertext-only-in-chrome) – James G. Sep 18 '14 at 15:54
  • @JamesG. `innerText` is not a standard property, it's one of Microsoft's own making which most other browsers recognise even though it's not part of the spec. The problem is that Firefox doesn't recognise it – Joe Sep 18 '14 at 15:57
  • @Joe Yeah, I was just linking a similar question that explored the problem. – James G. Sep 18 '14 at 15:59
  • If `lbResult` is a `
    `, then "\n" will work just fine.
    – 1983 Sep 18 '14 at 16:07

1 Answers1

1

You can't, as far as I know. You can do it with innerHTML though:

document.getElementById("lbResult").innerHTML = "<br />myID";
Joe
  • 15,669
  • 4
  • 48
  • 83