I have different strings in my array. Is it possible to create a divs like <div id="results"></div> for each array element in my HTML page?
<div id="results"></div>
Yeah, using a for loop:
for
var arrayVariable = ['one','two','three'], arrayLength = arrayVariable.length; for (i = 0; i < arrayLength; i++) { $('<div class="results" />').text(arrayVariable[i]).appendTo('body'); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
1.4m articles
1.4m replys
5 comments
57.0k users