You can add interactivity to DOM elements by assigning a function to run based on an event.

Events can include anything from a click to a user mousing over an element.

The .onclick property allows you to assign a function to run on a click event on an element:

let element = document.getElementById('interact'); element.onclick = function() { element.style.backgroundColor = 'blue' };



Modify the body of the turnButtonRed() function so that it modifies the button as follows:

  1. Assigns the .style.backgroundColor to 'red'
  2. Assigns the style.color to 'white'
  3. Modifies the .innerHTML to 'Red Button'

Add interactivity to the button element by adding a function that turns its .backgroundColor to 'red' and its font color to 'white' when the button is clicked.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?