JavaScript Curriculum
Event Types
easyThe coffee shop page needs live search as you type, keyboard shortcuts to navigate the menu, and a contact form that validates as you fill it in. Each feature needs a different event type.
Event Types
Every user interaction fires a specific event. Picking the right one matters — input fires on every keystroke while change only fires when the field loses focus. mouseenter doesn't bubble while mouseover does.
Event Type Gallery
Browse all major event categories and their use cases:
clickSingle click — left mouse button released
element.addEventListener('click', (event) => {
// handle click
console.log(event.type) // → 'click'
})Keyboard Events — Live Inspector
See exactly what the keyboard event object contains for any key combination:
// Common keyboard patterns:
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') submitForm()
if (e.key === 'Escape') closeModal()
if (e.key === 'ArrowUp') selectPrev()
// Detect shortcuts:
if (e.ctrlKey && e.key === 'k') openSearch()
})Mouse Events — Live Tracker
See mousemove, click positions, and clientX/Y in action:
const area = document.querySelector('.track-area')
area.addEventListener('mousemove', (e) => {
const rect = area.getBoundingClientRect()
const x = e.clientX - rect.left // relative to element
const y = e.clientY - rect.top
cursor.style.transform = `translate(${x}px, ${y}px)`
})
area.addEventListener('click', (e) => {
placeDot(e.clientX, e.clientY)
})Your Challenge
Wire the search input: input event → filter .card elements by matching h3.textContent.toLowerCase(). keydown event → if e.key === 'Escape' clear the input and show all cards. focus/blur → toggle a .focused class on the parent .search-group.
Challenge
Wire three event types on the search input: 'input' to filter cards as you type, 'keydown' to clear the field on Escape, and 'focus'/'blur' to add/remove a highlighted class on the input's parent.
Event Types
easyThe coffee shop page needs live search as you type, keyboard shortcuts to navigate the menu, and a contact form that validates as you fill it in. Each feature needs a different event type.
Event Types
Every user interaction fires a specific event. Picking the right one matters — input fires on every keystroke while change only fires when the field loses focus. mouseenter doesn't bubble while mouseover does.
Event Type Gallery
Browse all major event categories and their use cases:
clickSingle click — left mouse button released
element.addEventListener('click', (event) => {
// handle click
console.log(event.type) // → 'click'
})Keyboard Events — Live Inspector
See exactly what the keyboard event object contains for any key combination:
// Common keyboard patterns:
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') submitForm()
if (e.key === 'Escape') closeModal()
if (e.key === 'ArrowUp') selectPrev()
// Detect shortcuts:
if (e.ctrlKey && e.key === 'k') openSearch()
})Mouse Events — Live Tracker
See mousemove, click positions, and clientX/Y in action:
const area = document.querySelector('.track-area')
area.addEventListener('mousemove', (e) => {
const rect = area.getBoundingClientRect()
const x = e.clientX - rect.left // relative to element
const y = e.clientY - rect.top
cursor.style.transform = `translate(${x}px, ${y}px)`
})
area.addEventListener('click', (e) => {
placeDot(e.clientX, e.clientY)
})Your Challenge
Wire the search input: input event → filter .card elements by matching h3.textContent.toLowerCase(). keydown event → if e.key === 'Escape' clear the input and show all cards. focus/blur → toggle a .focused class on the parent .search-group.
Challenge
Wire three event types on the search input: 'input' to filter cards as you type, 'keydown' to clear the field on Escape, and 'focus'/'blur' to add/remove a highlighted class on the input's parent.