Events are actions that can be detected by JavaScript, and the event object gives information about the event that has occurred.
Sometimes we want to execute a JavaScript when an event occurs, such as when a user clicks a button.
Events are normally used in combination with functions, and the function will not be executed before the event occurs.
W3C: W3C Standard.
| Object | Description | W3C |
|---|---|---|
| dataTransfer | Represents a drag-and-drop operation | |
| event | Represents an object that contains information about an event that has occurred |
Below is the event attributes that can be inserted into different HTML elements to define event actions.
4: Indicates that the attribute is defined in HTML4.
5: Indicates that the attribute is defined in HTML5.
| Attribute | Description | HTML | HTML |
|---|---|---|---|
| onabort | 4 | 5 | |
| onbeforeonload | 5 | ||
| onbeforeunload | 5 | ||
| onblur | The event occurs when an element loses focus | 4 | 5 |
| onchange | The event occurs when the content of an element, the selection, or the checked state have changed | 4 | 5 |
| onclick | The event occurs when the user clicks on an element | 4 | 5 |
| oncontextmenu | 5 | ||
| ondblclick | The event occurs when the user double-clicks on an element | 4 | 5 |
| ondrag | The event occurs when an element is being dragged | 5 | |
| ondragend | The event occurs when an element has stopped being dragged | 5 | |
| ondragenter | The event occurs when an element has been dragged to a drop target | 5 | |
| ondragleave | The event occurs when an element leaves a valid drop target | 5 | |
| ondragover | The event occurs when an element is being dragged over a valid drop target | 5 | |
| ondragstart | The event occurs when drag operation has started | 5 | |
| ondrop | The event occurs when an element is being dropped | 5 | |
| onerror | The event occurs when an error occurs while loading an external file | 5 | |
| onfocus | The event occurs when an element gets focus | 4 | 5 |
| onkeydown | The event occurs when the user is pressing a key or holding down a key | 4 | 5 |
| onkeypress | The event occurs when the user is pressing a key or holding down a key | 4 | 5 |
| onkeyup | The event occurs when a keyboard key is released | 4 | 5 |
| onload | The event occurs when an object has been loaded | 4 | 5 |
| onmessage | 5 | ||
| onmousedown | The event occurs when a user presses a mouse button over an element | 4 | 5 |
| onmousemove | The event occurs when a user moves the mouse pointer over an element | 4 | 5 |
| onmouseover | The event occurs when a user mouse over an element | 4 | 5 |
| onmouseout | The event occurs when a user moves the mouse pointer out of an element | 4 | 5 |
| onmouseup | The event occurs when a user releases a mouse button over an element | 4 | 5 |
| onmousewheel | 5 | ||
| onreset | 4 | ||
| onresize | The event occurs when the size of an element has changed | 5 | |
| onscroll | 5 | ||
| onselect | The event occurs after some text has been selected in an element | 4 | 5 |
| onsubmit | 4 | 5 | |
| onunload | The event occurs before the browser closes the document | 5 |
| Property | Description | W3C |
|---|---|---|
| altKey | Returns whether or not the "ALT" key was pressed when an event was triggered | Yes |
| attrChange | ||
| attrName | ||
| bubbles | Returns a Boolean value that indicates whether or not an event is a bubbling event | Yes |
| button | Returns which mouse button was clicked when an event was triggered | Yes |
| cancelable | Returns a Boolean value that indicates whether or not an event can have its default action prevented | Yes |
| cancelBubble | ||
| charCode | ||
| clientX | Returns the horizontal coordinate of the mouse pointer, relative to the current window, when an event was triggered | Yes |
| clientY | Returns the vertical coordinate of the mouse pointer, relative to the current window, when an event was triggered | Yes |
| ctrlKey | Returns whether or not the "CTRL" key was pressed when an event was triggered | Yes |
| currentTarget | Returns the element whose event listeners triggered the event | Yes |
| data | ||
| dataTransfer | ||
| detail | ||
| dropEffect | ||
| effectAllowed | ||
| eventPhase | Returns which phase of the event flow is currently being evaluated | Yes |
| keyCode | ||
| metaKey | Returns whether or not the "meta" key was pressed when an event was triggered | Yes |
| newValue | ||
| origin | ||
| relatedNode | ||
| relatedTarget | Returns the element related to the element that triggered the event | Yes |
| pageX | ||
| pageY | ||
| prevValue | ||
| screenX | Returns the horizontal coordinate of the mouse pointer, relative to the screen, when an event was triggered | Yes |
| screenY | Returns the vertical coordinate of the mouse pointer, relative to the screen, when an event was triggered | Yes |
| shiftKey | Returns whether or not the "SHIFT" key was pressed when an event was triggered | Yes |
| source | ||
| srcElement | ||
| target | Returns the element that triggered the event | Yes |
| timeStamp | Returns the time stamp, in milliseconds, from the epoch (system start or event trigger) | Yes |
| toElement | ||
| type | Returns the name of the event | Yes |
| view | ||
| wheelDelta | ||
| which |
| Method | Description | W3C |
|---|---|---|
| addEventListener() | ||
| blur() | Removes focus from an element | Yes |
| clearData() | ||
| click() | Executes a click on an element | Yes |
| createEvent() | ||
| dispatchEvent() | ||
| focus() | Gives focus to an element | Yes |
| getData() | ||
| initEvent() | ||
| initMessageEvent() | ||
| initMouseEvent() | ||
| initMutationEvent() | ||
| initUlEvent() | ||
| postMessage() | ||
| preventDefault() | ||
| removeEventListener() | ||
| reset() | ||
| setData() | ||
| stopPropagation() | ||
| submit() |
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| Download XML Editor |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|