Javascript examples for DOM HTML Element:BR
You can create a <br> element by using the document.createElement() method:
In the following code, a br element is inserted before each span element in div.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">create some BR elements</button> <div id="myDIV"> <span>A</span> <span>B</span> <span>C</span> <span>D</span> </div>//from www . jav a 2s .co m <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>