0
[SOLVED]"document.body.getElementById()" does not work in SoloLearn?(Mobile)
I have been trying to use the function mentioned in the title but it does not work even though I was able to use that function before. https://code.sololearn.com/WQo9nDOBa2b4/?ref=app This code has same function that I am too lazy to write it here again and it does not work. removing ".body" makes it go totally crazy too.
5 odpowiedzi
+ 2
Yoi have to know that content of js tab on SL is injected like an inline script inside <head> tag of final html (that your browser render) than any call that get a dom element reference (like getElementById) return null because not dom is loaded yet... You have to call they AFTER dom is loaded then on window.onload callback or inside a DOMContentLoaded listener or put they in a function then call it from an inline script placed at bottom of <body> tag
+ 12
there is no "document.body.getElementById()" in js
it should "document.getElementById()"
+ 1
this.onload = function() {
var test = document.getElementById("pootis");
if(test === null) {
console.log("Does not exist");
}else{
console.log("Does exist")
}
test.innerHTML = "its here";
};
0
Amethyst Animion I was used to use it on Chrome v46. normal version wasn't working. Give it a try on desktop Chrome's console!