<!DOCTYPE html> <html> <head> <script> document.getElementById("passage").innerHTML = "Paragraph changed!"; </script> </head> <body> <div id="passage">hello</div> <div id="question"></div> <div id="answers"></div> </body> </html>
Why is document.getElementById("passage").innerHTML = "Paragraph changed!"
not working for me? I just end up with a blank screen, not even the original “hello”.
Advertisement
Answer
Your script is called before the element is loaded, try calling the script after loading element
<!DOCTYPE html> <html> <head> </head> <body> <div id="passage">hello</div> <div id="question"></div> <div id="answers"></div> <script> document.getElementById("passage").innerHTML = "Paragraph changed!"; </script> </body> </html>