i++ and showing the value on innerHTML
Posted: Tue Mar 03, 2009 8:31 am
Hello, I have the code below which writes the values but how to assign them to an id with innerHTML?
I tried:
But it did not work 
Code: Select all
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>Code: Select all
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
document.getElementById("anyId").innerHTML = i + "<br>";
}
</script>
<span id="anyId"></span>
</body>
</html>