This is not how javascript works. This is something you would do with PHP.
With javascript, you run it seperately from the html. Then, you create an element within your html as a wrapper to put the javascript generated html into. Like so:
HTML
<div id="myHTMLWrapper">
</div>
<script>
var wrapper = document.getElementById("myHTMLWrapper");
var myHTML = '<span class="test">Testing out my script!</span>';
wrapper.innerHTML = myHTML
</script>
See a working example here
Sorry I skipped over the for
loop by the way. Let me fix it with this update... You could do it like this, you see:
<script>
var wrapper = document.getElementById("myHTMLWrapper");
var myHTML = '';
for (var i = 0; i < 10; i++) {
myHTML += '<span class="test">Testing out my script! loop #' + (i + 1) + '</span><br/><br/>';
}
wrapper.innerHTML = myHTML
</script>
if
does ...