Smal SEO Tool

JavaScript Events

HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events.

Common HTML Events

Here are some examples of HTML events:

  • An HTML web page has finished loading
  • An HTML input field was changed
  • An HTML button was clicked

Example: onclick Event

The onclick attribute executes a piece of JavaScript when the element is clicked.

html
<button onclick="document.getElementById('demo').innerHTML = Date()">The time is?</button>
Try it Yourself

Test Yourself with an Exercise

Which event occurs when the user clicks on an HTML element?