9

I have this code:

elf='%0A';
document.getElementById('writebox').innerHTML=("hello there"+elf+"friend");

When the function that this is inside is called, the text that appears in the div is not a line break, but rather just "%0a". This confuses me, because inside another different function, elf works fine. Any ideas why?

  • Inside ordinary HTML the linefeed is ignored by the browser - use
    instead. Why it may work in another area is that the html element could be either a textarea or a pre tag
    –  Jul 29 '15 at 02:21

1 Answers1

20

Different encoding. %0A is URL-encoding of a newline, which you would use in (obviously) URLs. &x0a; would be the HTML-encoding of the same character that you would use in HTML, but it doesn't work, for a variety of reasons. To break a line in HTML, you can use <br> tag.

EDIT:

the problem wit a <br /> tag is that all i want is simply a new line. <br /> creates WAY too much white space

No, it doesn't:

foo<br>
bar
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • the problem wit a
    tag is that all i want is simply a new line.
    creates WAY too much white space.
    –  Jul 29 '15 at 02:24
  • 3
    @Mr.Chameleon In that case, [style the `
    `](http://stackoverflow.com/questions/1409649/how-to-change-the-height-of-a-br) tag with CSS to make it appear like you'd like it to
    – War10ck Jul 29 '15 at 02:26