In the previous tutorial, you saw how to edit HTML using JavaScript.
In this tutorial, you will learn how to trigger a JavaScript function to run when a user does something, such as click on a button. This will allow you to change the HTML page in reaction to actions taken by the user on your website.
User clicking on a button is one of many types of events supported by JavaScript. You'll see another event in the next tutorial — submitting forms. And then many more over the remaining tutorials in this course.
Overview
As a small example of how to trigger JavaScript functions when an event happens, we will start by making an HTML page which changes when the user clicks a button. To do this, we need to do the following:
- Create an HTML page with a <button> element
- Write a JavaScript function to change the style properties of <body>
- Connect the button to the JavaScript function.
Let's get started!