I'm trying add a newline after some text every time a button is pressed. Here is the part of HTML file concerning the question -
<input type="text" id="fname" name="fname">
<button type = "button" onclick = "prtText('fname')">SEND</button>
<p id="para"></p>
<script>
var node = document.createElement("P");
function prtText(addr)
{
var x = document.getElementById(addr).value;
var txt = x + '\n'
var textnode = document.createTextNode(txt);
node.appendChild(textnode);
document.getElementById("para").appendChild(node);
}
</script>
Now, when I run the HTML file, every time I press the button, the text on the input box should get printed with a newline. Like this-
ExampleText
ExampleText
But it gets printed something like this-
ExampleText ExampleText
.
I have tried the other method like this - var txt = x + '<br/>'
, but it prints like this - ExampleText<br/>ExampleText<br/>
and doesn't print a line break.
What do I do?