JavaScript JavaScript and the DOM Getting a Handle on the DOM Select All Elements of a Particular Type

Winnie Kelley
Winnie Kelley
Full Stack JavaScript Techdegree Student 13,938 Points

.addEventListener error after pressing button to change colour.

I have the same code as the video, the page will load up on preview. However, when I put in a colour and try and press the button. the error of "Cannot read property 'addEventListener' of null" will be displayed in the console.

const myHeading = document.getElementById('myHeading'); const myButton = document.getElementById('myButton'); const myTextInput = document.getElementById('myTextInput');

myButton.addEventListener("click", () => { = myInputText.value; });

1 Answer

54,332 Points

I received a different error

Uncaught ReferenceError: myInputText is not defined
    at HTMLButtonElement.<anonymous> (app.js:14)

This is because you declare myTextInput but then in your event listener use myInputText