When the user manipulates a page, events may be occurred. Events are fired inside the browser window and tend to be attached to a specific item that resides in it which may be a single element, set of elements, the HTML document loaded in the current tab, or the entire browser window. JavaScript's interaction with HTML is handled through events. Events are occurred whenever a page is loaded (page load event), the user clicks a button (button click event) or on pressing any key, closing a window, resizing a window, etc.
Some more types of events may occur on:
The occurrence of these events may be used by the Programmers to execute responses coded in JavaScript like cause buttons to close windows, messages to be displayed to users, data to be validated, or any other type of response
Event | Description |
---|---|
onchange | An HTML element has been changed |
onclick | The user clicks an HTML element (button, image etc) |
onmouseover | The user moves the mouse over an HTML element |
onmouseout | The user moves the mouse away from an HTML element |
onkeydown | The user pushes a keyboard key |
onload | The browser has finished loading the page |
This is a mouse event and provokes the code written if the user clicks on the element it is bound to.
Code:
Examples
Button Click Event
Output: after page is loaded.
Output: after the button is clicked