To make a tag on a webpage findable in an included script, the tag needs an identifier, or ID.

Code id to create an id attribute for the heading tag.

<body><h1 id="mainTitle">US elections</h1><script></script></body>
</html>]]>

Make sure to add id to your code.