JavaScript events are actions that occur in the browser, such as clicking a button, submitting a form, pressing a key, or moving the mouse. JavaScript allows us to handle and respond to these events dynamically.
Event | Description |
---|---|
click |
Fires when an element is clicked. |
mouseover |
Fires when the mouse is over an element. |
mouseout |
Fires when the mouse leaves an element. |
keydown |
Fires when a key is pressed. |
keyup |
Fires when a key is released. |
change |
Fires when an input value changes. |
submit |
Fires when a form is submitted. |
load |
Fires when the page or an element loads. |
<button onclick="showMessage()">Click Me</button>
<script>
function showMessage() {
alert("Button Clicked!");
}
</script>
💡 Not recommended for larger projects due to maintainability issues.