JavaScript JavaScript and the DOM Getting a Handle on the DOM Select a Page Element By Its ID

Marcel Carey
Marcel Carey
2,890 Points

Uncaught TypeError: Cannot read property 'value' of null

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <h1 id="myHeading">JavaScript and the Dom</h1>
    <p>Making a web page interactive</p>
    <input type="text" id="MyTextInput">
    <button id="myButton">Change headline color</button>

    <script src="js/app.js"></script>

let myHeading = document.getElementById('myHeading')
let myButton = document.getElementById('myButton')
let myTextInput = document.getElementById('myTextInput')

myButton.addEventListener('click',function(){ = myTextInput.value
} )

2 Answers

Steven Parker
Steven Parker
203,727 Points

The input element in the HTML has an ID of "MyTextInput" (with capital "M"), but the JavaqScript code is trying to get an element with id of "myTextInput" (lower-case "m").

Marcel Carey
Marcel Carey
2,890 Points

OH geez. Thanks so much for your help