What’s hard-coded in your HTML file when the page loads can still be changed by your JS.
Consider this HTML:
<div id="intro">
<p id="p1">This is text 1</p>
<p id="p2">This is text 2</p>
</div>
Next I will take control of the div
const div1 = document.getElementById('intro')
And I will empty it’s innerHTML
div1.innerHTML = ''
And now I will try to take control of the p
tag with the id p1
const p1 = document.getElementById(‘p1’)`
And I get an error! Because when I update the innerHTML of the div I change all of the HTML in that div! So the p
tag with an id of p1
no longer exists even though it’s in my html.