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

Daniel McHugh
Daniel McHugh
1,821 Points

Arrow syntax not working?

This code from the video is not working when I use arrow syntax to replace the function. What am I doing wrong? Here's the screenshot: https://w.trhou.se/jqd9s1k8rw It works perfectly when I replace it with a normal function.

We can't see your code.

Jennifer Nordell
Jennifer Nordell
Treehouse Moderator

Hi there! Thanks for including the link to your workspace so that we can see your code. I'm a bit curious as to what browser and what version of the browser you're using. When I fork your workspace and replace the normal function with an arrow syntax function, it works for me. So I'm wondering if it's supported in your browser.

That being said, it would be nice if you had left the arrow syntax that you tried in instead of the function that does actually work so that we can rule out errors there. :sparkles:

Daniel McHugh
Daniel McHugh
1,821 Points

Here is an updated screenshot: https://w.trhou.se/ek2eiidvkn

and here is the code: const myHeading = document.getElementById("myHeading"); const myButton = document.getElementById("myButton"); const myTextInput = document.getElementById("myTextInput");

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

Jennifer Nordell
Jennifer Nordell
Treehouse Moderator

Hi again, Daniel! I just forked the new one and there's good news and bad news. The good news is that it works on my end.! I click the button and the headline changes to red. But the bad news is that I still don't know why you're not seeing what I'm seeing. So once again, what browser are you using and what version? Because it may very well be that you're using a browser where arrow syntax simply isn't supported.

As Jennifer said, it works correctly for me too, I am using the latest Google Chrome. Cheers.

Daniel McHugh
Daniel McHugh
1,821 Points

Okay, thanks everyone. I'm at work using IE 11 since it's the only browser available. I'll just write it out the long way while I'm using this browser.

1 Answer

Steven Parker
Steven Parker
163,760 Points

The browser is the issue. According to Can I Use?, IE 11 does not support arrow functions.