JavaScript
x
19
19
1
<!DOCTYPE html>
2
<html>
3
4
<head>
5
<script>
6
document.getElementById("passage").innerHTML = "Paragraph changed!";
7
</script>
8
</head>
9
10
<body>
11
12
<div id="passage">hello</div>
13
<div id="question"></div>
14
<div id="answers"></div>
15
16
</body>
17
18
</html>
19
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
JavaScript
1
14
14
1
<!DOCTYPE html>
2
<html>
3
<head>
4
</head>
5
<body>
6
<div id="passage">hello</div>
7
<div id="question"></div>
8
<div id="answers"></div>
9
<script>
10
document.getElementById("passage").innerHTML = "Paragraph changed!";
11
</script>
12
</body>
13
</html>
14