20 min25 XP

What are Events

Introduction to Interactive Programming

Step 1 of 5

What are Events?

Events are things that happen in the browser that JavaScript can respond to. Think of events like signals that say "something just happened!"

Common Events:

  • Click: User clicks on something
  • Hover: Mouse moves over something
  • Keypress: User types on keyboard
  • Submit: User submits a form
  • Load: Page finishes loading

Why Events Matter

Events make your website interactive! Without events, websites would just sit there. Events let you respond to what users do:

  • When they click a button
  • When they type in a search box
  • When they hover over a menu
  • When they submit a form
// Simple event example
button.addEventListener('click', function() {
console.log('Button was clicked!')
})

This code says: "When the button is clicked, run this function!"