DOM and events: Keyboard-friendly buttons
A native button already supports keyboard activation. A click listener can serve mouse, touch, and keyboard users.
Current edit
Understand the pattern
A native button already supports keyboard activation. A click listener can serve mouse, touch, and keyboard users.
A native button already supports keyboard activation. A click listener can serve mouse, touch, and keyboard users.
Misconceptions to reject
- A string containing code executes automatically when it is assigned.
- A successful element lookup guarantees that the rest of an event handler is correct.
This is a code-inspection lab, not a full JavaScript runtime.
Worked example and expected result
const button = document.querySelector("#start");
function activate() { button.textContent = "Activated"; }
if (button) { button.addEventListener("click", activate); }A native button already supports keyboard activation. A click listener can serve mouse, touch, and keyboard users.
Explain it
Apply it elsewhere
Keep the momentum.
Complete the lab, then explain and apply the pattern.
Next: DOM and events: Status announcementsTry an incident drillAnonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.
Keep learning
- 01DOM and events: Data attributesdataset exposes data-* values as strings; data-lesson-id becomes dataset.lessonId.Practice
- 02DOM and events: Status announcementsUpdating an existing live region can communicate a status without moving focus away from the user.Practice
- 03DOM and events: DOM behavior checkpointA reliable interaction finds its elements, guards their absence, and makes one deliberate update in response to an event.Practice