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

Mariana Castilho
Mariana Castilho
Front End Web Development Techdegree Graduate 13,842 Points

Why can't I do in this way

I tried a different code, but when I click on the heading element the color doesn't change...is there any difference? I thought that the inputColor const should store the value from the input and it should change the heading color when the user clicks on it.

const myHeading = document.getElementById('myHeading');
const inputColor = document.getElementById('input-color').value;


myHeading.addEventListener('click', () => {
                           myHeading.style.color = inputColor

                           });

1 Answer

inputColor will take the value at the time it is assigned which is blank