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

Fredrik Johansson
Fredrik Johansson
Full Stack JavaScript Techdegree Student 6,371 Points

Sharing my solution/code

//Declaring an arrow function which styles the ID "myHeading" with a red color. Putting the function in a const variable named changeColor. Since the function doesn't have any parameters I need to use parenthesis. And since there's not a multi-line I can build everything in one line.

const changeColor = () => {document.getElementById('myHeading').style.color = 'red';}

//Calling the function once the ID "myHeading" is clicked.

document.getElementById('myHeading').addEventListener('click', changeColor);

2 Answers

Looking great but because you don't have any parameters doesn't mean you should use the arrow function. You also don't need curly braces.

This is a good read.