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

julian Ellis
julian Ellis
3,542 Points

Code not working

Can't get the following code to work in any browser

var myHeading = document.getElementById('myHeading'); myHeading.addEventListener('click', function() { myHeading.style.color = 'red'; });

1 Answer

Stephan Olsen
Stephan Olsen
6,645 Points

The code seems to be working for me. Make sure that you're linking to the js file in which you have the code.

Nguyen Quach
Nguyen Quach
1,827 Points

I had the same problem until i realized i created the app.js file in the css folder. I had to move it back in the root folder.