JavaScript imported incorrectly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

JavaScript imported incorrectly?

Hi. I have tried to add a JavaScript (over the js tab) to my html5 document. but for some reason, it seems to be imported too early. i have checked other codes and they work while they seem to to the same as mine. i cant find the problem... help would be appreciated! https://code.sololearn.com/W3V7JaSk0FZz/?ref=app

19th Aug 2017, 8:46 PM
Cook1ee
3 Answers
+ 2
First your break tag is incorrect: </br> the backslash isn't needed, but if you're wanting to make it xml compatible you can use <br/> instead and the browser won't usually complain. Next in your line: <progress min="0", max="100", value="11"></progress> the syntax is incorrect you need to remove the comma's <progress min="0" max="100" value="11"></progress> Finally the issue you're having has to due with the DOM not being created prior to trying to access it. SL injects the JS in the JS tab in the head section and is loaded prior to the body of the page. You can wrap your code in a window.onload or similar jQuery document.ready etc to resolve the issue. window.onload = function() { var i = 12; document.getElementById("vartext").innerHTML = i; }
19th Aug 2017, 8:57 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
code your JavaScript in html under <script> tag. This will solve your problem.
19th Aug 2017, 8:59 PM
Anshul Shrivastava
Anshul Shrivastava - avatar
0
Thanks for your answers. I will include the script in the html doc then
19th Aug 2017, 9:06 PM
Cook1ee