I want to display an array's content(more than 1k elements) line by line within the <p></p> element when click a button, but they output simultaneously after finished the for loop. Here is a simplified version of my HTML file:
<html>
<body>
<p id='demo'>append below: <br/></p>
<script>
function clickTest() {
var cars = new Array("Audi", "BMW", "Volvo");
paraElement = document.getElementById("demo");
for (var i = 0; i < cars.length; i++) {
paraElement.innerHTML += cars[i] + "<br>";
}
}
</script>
<button type="button" onclick="clickTest()">Click Me!</button>
</body>
</html>
Could anyone tell me how to output the array line by line, instead of simultaneously displayed?
via Patrick
No comments:
Post a Comment