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

Shyam Gupta
PRO
Shyam Gupta
Pro Student 6,706 Points

"Uncaught ReferenceError: myheading is not defined"

const myHeading = document.getElementById("myHeading");
    myHeading.addEventListener('click', () =>{
    myHeading.style.color = 'red';      
});```

1 Answer

Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,252 Points

Make sure the id you're using in the HTML is spelled exactly the same as the name you pass to getElementById() and that it is an id and not a class.

Shyam Gupta
Shyam Gupta
Pro Student 6,706 Points

Thanks Seth..It ultimately turned out to be Chrome caching old data..I relaunched the browser and disabled cache in the JS console Network tab and it works fine now.