<!DOCTYPE html>
<html>
<body>
<p>Click the button to create some BR elements.</p>
<button onclick="myFunction()">Try it</button>
<p>When you click the button, a br element is inserted before each span element in div, causing an appropriate line break in the text below.</p>
<div id="myDIV">
<span>Hello,</span>
<span>My name is Bob.</span>
<span>I live in Bobville.</span>
<span>I am 45 years old.</span>
</div>
<script>
function myFunction() {
var div = document.getElementById("myDIV");
var spans = div.getElementsByTagName("SPAN");
var i;
for (i = 1; i < spans.length; i++) {
var newElem = document.createElement("BR");
div.insertBefore(newElem, spans[i]);
}
}
</script>
</body>
</html>