+ 1
Javascript Not Working
The coding in the url work perfectly in browser in my pc but somehow does not work normally in sololearn. How can i solve this issues ? 1) Cant use eventlistener. 2) Cant use .innerHTML https://code.sololearn.com/WWhk0OTR5yex
2 Answers
+ 7
first, try wrapping the JS code with
window.onload = function(){
..... all your code here .....
}
this will ensure that your HTML is rendered before you are attempting to access it using JS
second, when using getElementById the '#' symbol is not required (same goes for '.' in getElementsByTagName)
so remove those and see where your code stand at
+ 1
Execute the code when the DOM is available.
addEventListener("DOMContentLoaded", function (){
[code]
});
This is normally better than window.onload