Check out my code snippet:
<script>
var change = function(){
alert("sam");
for(var i; i >=200; i++){
var z = String(i);
var x= document.getElementById("div1");
x.style.width = z;
}
};
</script>
<style type="text/css">
#div1{
width:100px;
height: 100px;
background-color:#ccc;
}
</style>
<div id="div1"></div>
<button onclick="change();"> click</button>
This code is designed to increase the width of a div container, similar to jQuery animations. I'm attempting to achieve this effect using plain JavaScript.
I ran this code in Google Chrome and encountered no errors. However, the width of the div did not change as expected. Strangely enough, the code did trigger an alert with the message sam
!
If you can spot any mistakes in my code, please let me know. Thank you!