+ 1

Why does code playground throw an error stating "cannot set property 'innerHTML' of null" it works on my txt editor [Android]?

Is there a work around for this? The code is as follows there may still be errors the code is public on my profile: <html> <head> <style> body { background-color: black; color: green; } </style> <script type="text/javascript"> alert("This is your current [Password]"); function scroll(position) { var passScroll = "This is a sampleThis is a sample This is a sample"; var out = ""; var sc = document.getElementById('pswScroller'); for(i = 0; i < position; i++) { out += passScroll.charAt(i); } out += passScroll.charAt(position); sc.innerHTML = out; position++; if (position != passScroll.length) { window.setTimeout(function() { scroll(position); }, 50); } else { window.setTimeout(function() { scroll(0);}, 30000); } } scroll(0); 8 </script> </head> <body> <p id="pswScroller"></p> </body> </html>

26th Apr 2019, 10:35 AM
Cyrus The Virus!
Cyrus The Virus! - avatar
3 ответов
+ 8
add window.onload = function(){ at the first line and add } at the end
26th Apr 2019, 1:43 PM
Naola
Naola - avatar
+ 2
dang didnt even think about window.onload will try thanks
26th Apr 2019, 2:20 PM
Cyrus The Virus!
Cyrus The Virus! - avatar
+ 2
like a charm thx
26th Apr 2019, 2:26 PM
Cyrus The Virus!
Cyrus The Virus! - avatar