user6866603 user6866603 - 1 year ago 65
HTML Question

How to insert twice of space "& nbsp " for each new line

I create an array with "split" and "join" when the array jump to a new line insert twice as much space as the previous and send it to a < p> by GetElementById.
This is my code:

<script type="text/javascript">
function myfunction() {

<p id="msg"></p>

var x= document.getElementById("input").value;

var text = x.split("\u0020").join(" <br/> ");

document.getElementById("msg").innerHTML = text;



Answer Source

consider using .reduce() instead of .join() - it gives much more flexibility at processing individual values and their concatenation.

But before that, you are declaring your <p> element inside <script> tag - this most probably won't work at all, move it to somewhere before script tag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download