+ 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

2nd Feb 2018, 9:38 AM
Soo Kin Wah
Soo Kin Wah - avatar
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
2nd Feb 2018, 11:16 AM
Burey
Burey - avatar
+ 1
Execute the code when the DOM is available. addEventListener("DOMContentLoaded", function (){ [code] }); This is normally better than window.onload
2nd Feb 2018, 11:28 AM
Draphar