0

So,I have a problem with writing some text(h2) with new line,I created the new line by '\n'.It writes it right into the console,but as h2 element it writes it in one line. Code :

     <h2 id="T4"></h2>
    
      <script type="text/javascript">
    
    
    
      var TEST = 'a' + '\n' + 'b'
      console.log(TEST)
    
    document.getElementById("T4").innerHTML = TEST
    </script>
Adolf Weii
  • 23
  • 6

1 Answers1

0

You need to use the HTML special line break tag <br/> like this:

     <h2 id="T4"></h2>
    
      <script type="text/javascript">
    
    
    
      var TEST = 'a' + '<br/>' + 'b'
      console.log(TEST)
    
    document.getElementById("T4").innerHTML = TEST
    </script>
Namefie
  • 117
  • 1
  • 2
  • 14