+ 6
Does Javascript document.getElementById function in SoloLearn editor?
Please answer. I've a snippet of code with document.getElementById functioning in browser, but it seems it returns null in SoloLearn editor: var elem = document.getElementById('para'); elem.style.color = newColor; and in HTML body: <p id="para">a paragraph</p>
2 odpowiedzi
+ 3
The problem is that the js file is probably automatically loaded in the header or beginning of the body document by SoloLearn. What you need to do is
window.onload = () => {
elem = document.getElementById(`para`)
elem.style.color = newColor
}
+ 2
Paolo
You could check someone else code to find the answer to your question
https://code.sololearn.com/WuSoJtZrSlrU/#js
The more likely problem is your code itself, you should provide a link to allow a community member to help you get to the root of your problem.
btw- Check newColor