+ 7

i am trying to create an animation with JS and has a linewith obj.style.left but displays that it cannot read the property style

please i am trying to create an animation with Javascript and has a linewith obj.style.left but displays that it cannot read the property style

27th Nov 2017, 2:32 PM
King FrankosteinĀ®
King FrankosteinĀ® - avatar
4 Answers
27th Nov 2017, 2:38 PM
King FrankosteinĀ®
King FrankosteinĀ® - avatar
+ 5
how do I stop the animation from executing unless the button is pressed https://code.sololearn.com/WkdtOeZjB0QP/?ref=app
27th Nov 2017, 6:11 PM
King FrankosteinĀ®
King FrankosteinĀ® - avatar
+ 1
Post your code?
27th Nov 2017, 2:34 PM
AgentSmith
+ 1
<script> var t= setInterval(gunned,500); var ini = 0; //our box element var bullet = document.getElementById("bullet"); function gunned() { ini += 1; bullet.style.left = ini+"px"; } </script> ^Post your JS script at the bottom of your HTML <body>. Basically, it's loading your script before it loads the HTML, so the element with the ID "bullet" doesn't exist at the time that JS checks. If you put it at the bottom of your HTML, it'll load the HTML first before it loads your script, thus the element "bullet" will exist at that time. Hope that helps.
27th Nov 2017, 2:51 PM
AgentSmith