Your marquee
element does not have a firstChild
. Your code will work as it is if you give it a default value:
<marquee behavior="scroll" direction="left" id="marquee">Default</marquee>
Alternatively, you can set its textContent
(or innerText
where appropriate):
document.getElementById("marquee").textContent = "New Text";
But marquee
... really?! I'd suggest looking at alternative solutions.