Skip to content Skip to sidebar Skip to footer

Javascript Needs To Send Esc Character \n Or Text Return

To Html/browser

1) When executing JavaScript in the interpreter - I can use an esc sequence to put some text on a second line NOTE: the value of myHeading.textContent was different in this screen

Solution 1:

Whilst your shell does understand what \n represents, modern browsers do not. To represent a newline on a web page, you should use the <br> element instead.

Now, as you've already experienced, you cannot interpolate an HTML element using the textContent property. This is because the textContent property represents the text of an element, not the html -- any string you set will be treated as text.

To set the inner html of an element, use the innerHTML property.

Something like this should work for your needs:

myHeading.innerHTML = 
    'Good to see you again, ' + storedName +  ' <br>  Write me again soon.' ;

Post a Comment for "Javascript Needs To Send Esc Character \n Or Text Return

To Html/browser"