html - Count to 100 using Javascript (in a div) -
this question has answer here:
i wanne count 100 in div using javascript. why comes last number.
here code:
function test() { for (var x = 1; x < 101; x++) { document.getelementbyid("demo").innerhtml = (x + "<br />"); } }function leer() { document.getelementbyid("demo").innerhtml = "delete" }
<html> <head> <script src="function.js"></script> </head> <body> <button type="button" onclick="test()">100</button> <button type="button" onclick="leer()">delete</button> <div id="demo"> </div> </body> </html>
change document.getelementbyid("demo").innerhtml += (x + "<br />");
line
function test() { for (var x = 1; x < 101; x++) { document.getelementbyid("demo").innerhtml += (x + "<br />"); } }function leer() { document.getelementbyid("demo").innerhtml = "delete" }
<html> <head> <script src="function.js"></script> </head> <body> <button type="button" onclick="test()">100</button> <button type="button" onclick="leer()">delete</button> <div id="demo"> </div> </body> </html>
Comments
Post a Comment