Unable to show "\t" on the web page when it has been inserted using javascript into div.
Take a look at below code snippet. The first div shows "\t" as text but when they are inserted into div using javascript, they get rendered by the browser and not displaying it as text on UI.
I need to insert text in div using javascript, the text contains "\t" character and I need to show them as it is, without rendering it.
I looked at many similar questions on stackoverflow, but none of them really worked. Please advise.
function callme() {
document.getElementById('div2').innerHTML = "I am div 2, tab char 1:\t , tab char 2: \t";
}
<!DOCTYPE html>
<html>
<body>
<span id='div1'>I am div 1, tab char 1: \t , tab char 2: \t</span>
<br /> <br /> <br />
<button onclick="callme()">Click me to Insert tab characters in below div</button>
<br /> <br />
<span id='div2'>I am div 2, click above button insert tab characters</span>
</body>
</html>