JavaScript JavaScript and the DOM Getting a Handle on the DOM A Simple Example

Albin Rohde
Albin Rohde
2,304 Points

Code not working?

might just be a typo or simple mistake, anyways.

index.html
<body>
    <h1 id="myHeading">JavaScript and the DOM</h1>
    <p>Making a web page interactive</p>
    <script src="app.js"></script>
  </body>
app.js
const myHeading = document.getElementByID('myHeading');

myHeading.addEventListener('click', () => {
    myHeading.style.color = 'red';
});

1 Answer

Albin Rohde
Albin Rohde
2,304 Points

THIS IS SOLVED!

Typo in document.getElementByID('myHeading'); where ID is in caps, instead of Id.