Hi. i'm javascript beginner. My problem is that i can't evaluate where and how to inject </ br> tag, to get names of my cars looking like a list. Thanks in advance! The code is: function show_cars () { var div = document.getElementById('id') var cars = new Array(); cars[0] = "Volvo"; cars[1] = "Ferrari"; cars[2] = "BMW"; for(x in cars) { var txt = cars[x]; var new_txt = document.createTextNode(txt); div.appendChild(new_txt); } }
<div id="cars"></div> <script type="text/javascript"> function show_cars () { var div = document.getElementById('cars') var cars = new Array(); cars[0] = "Volvo"; cars[1] = "Ferrari"; cars[2] = "BMW"; for(x in cars) { var txt = cars[x]; var new_txt = document.createTextNode(txt); var new_br = document.createElement('br'); // Br Tag Created div.appendChild(new_txt); div.appendChild(new_br); // Br tag Appended after Each text node } } show_cars (); </script> Code (markup):