Hello guys, as you can see I tried to keep my code clean with breaking a template string into multiply lines. Unfortunately it didn´t work like I thought. After breacking the template String into multiple lines the html is also now broken into multiply lines. I didn´t do that with the massEl.innerText. thats why its in one line. Could someone help? Edit: fixed the problem with changing .innerText to innerHTML. But that was some sort of lucky strike...could someone explain why it worked with innerHTML but not with innnerTExt?
#Clean code and getting a sentence in one line
1 messages · Page 1 of 1 (latest)
The problem is the innerText property... The MDN documents say:
"As a setter this will replace the element's children with the given value, converting any line breaks into <br> elements."
In your case I would suggest that instead of EITHER of these you use the .textContent property - innerHTML is really intended for injecting markup (including tags) which you don't require .
Hi ! For your question, It has to do with how innerHtml and innerText interpret line break. innerHtml don't care for it, like actual html, which means if you write a <p>, then do 20 lines breaks on your code to see it more clearly, and then write another <p>, the two <p> will still appear close together in your actual page. The line break in your code are not interpreted / rendered.