- In this case, consider an event to be any action, property, or change that can be tested for, such as when something on a web page is clicked or hovered over. Events work the same way logically that they do in real life. Say, for example, if you were to insert your house key into your front door. On the event that you turn your key to unlock it, your door will become unlocked. If we were to replicate this event through programming, we would run a function that would probably be called unlockDoor() on the event that a key is inserted and turned.
onClick is the main event we will focus on.
- You may first think of a button when you’re thinking of putting this event to use, but the onClick event can be applied to any HTML element.
- We have already coded the onClick attribute in our HTML on the button element, so now we need to declare the eraseContent() function. This function does not need to take any parameters.