Great work learning to change content and styles! Now let's explore how web pages respond to user actions like clicks and key presses.
These user actions are called events—they're signals that fire when users interact with your page.
Engagement Message
What's one action you take on websites that might trigger an event?
Events happen constantly on web pages. Every time you click a button, move your mouse, or type on your keyboard, your browser is creating events.
Think of events as broadcast signals that tell JavaScript, "Hey, something just happened!"
Engagement Message
Can you think of an event that doesn't involve a mouse?
The most common event is click
. It fires when someone clicks on an element with their mouse or taps it on a touch screen.
Buttons, links, images, and even regular text can all be set up to respond to click
events.
Engagement Message
What elements on a typical website would you expect to be clickable?
Another useful event is mouseover
. It happens when someone moves their mouse cursor over an element. mouseout
happens when the cursor leaves.
This is perfect for creating hover effects, like highlighting a button or showing a tooltip when the cursor moves over it.
Engagement Message
How might a mouseover
event improve user experience?
