Welcome to the JavaScript Events ! This repository helps you understand and practice handling events in JavaScriptโespecially keyboard and mouse events.
Youโll also explore the powerful event
object and its most useful properties.
- ๐ Introduction
- ๐ฑ๏ธ Mouse Events
- โจ๏ธ Keyboard Events
- ๐ฆ The
event
Objectevent.target
event.key
event.clientX
/event.clientY
In JavaScript, events are actions that occur in the browserโlike clicking a button, pressing a key, or moving the mouse. We can use event listeners to detect these actions and run custom code in response.
Commonly used mouse events in JavaScript:
click
: User clicks an elementdblclick
: User double-clicksmousedown
: Mouse button is pressedmouseup
: Mouse button is releasedmousemove
: Mouse pointer movesmouseenter
/mouseleave
: Pointer enters or leaves an element
Keyboard events allow us to respond to user key presses:
keydown
: Triggered when a key is pressedkeyup
: Triggered when a key is releasedkeypress
: (Deprecated) Avoid using in modern code
When an event occurs, JavaScript creates an event
object containing useful info about the event.
- Refers to the element that triggered the event.
- Returns the actual key the user pressed (like "a", "Enter", "1").
-
clientX: X-coordinate (horizontal) of the mouse relative to the viewport
-
clientY: Y-coordinate (vertical) of the mouse relative to the viewport
Documented by Paras Jindal as part of a structured roadmap to mastering JavaScript and web development fundamentals.