HTML5 global attributes and events, HTML5 global attribute events
Abstract:
Global attributes and events can be applied to all tag elements. There are many global attributes such as id and class in html4. Some special features such as Global attributes and events are added to HTML5.
Attribute:
HTML5 attributes can be assigned the meaning and context of tag elements. The following global attributes can be used for any HTML5 element.
Attribute |
Description |
Contenteditable |
Specifies whether users are allowed to edit content. |
Contextmenu |
Specifies the context menu of an element. |
Draggable |
Specifies whether to allow users to drag elements. |
Dropzone |
Specifies what happens when the dragged Project/data is dragged to an element. |
Hidden |
This element is not required. Hidden elements are not displayed. |
Spellcheck |
Specifies whether spelling or syntax checks must be performed on elements. |
Event:
The global event attributes added to HTML5 elements to define event actions are listed below.
Window event
Events triggered for window objects (applied to the <body> tag ):
Attribute |
Value |
Description |
Onafterprint |
Script |
The script that runs after the document is printed. |
Onbeforeprint |
Script |
Print the script that was run before. |
Onbeforeunload |
Script |
This document uninstalls the previously run script. |
Onerror |
Script |
The script that runs when an error occurs. |
Onhaschange |
Script |
The script that runs when the document has changed. |
Onmessage |
Script |
The script that runs when the message is triggered. |
Onoffline |
Script |
The script that runs when the document is offline. |
Ononline |
Script |
The script that runs when the document goes online. |
Onpagehide |
Script |
The script that runs when the window is hidden. |
Onpageshow |
Script |
The script that runs when the window is visible. |
Onpopstate |
Script |
The script that runs when the window history changes. |
Onredo |
Script |
The script that runs when the document executes the Undo (redo) operation. |
Onresize |
Script |
Triggered when the browser window is changed. |
Onstorage |
Script |
The script that runs after the Web Storage region is updated. |
Onundo |
Script |
The script that runs when the document executes the undo operation. |
Form event
Events triggered by actions in an HTML form (applied to almost all HTML elements, but most commonly used in form elements ):
Attribute |
Value |
Description |
Oncontextmenu |
Script |
The script that runs when the context menu is triggered. |
Onformchange |
Script |
The script that runs when the form is changed. |
Onforminput |
Script |
The script that runs when the user inputs the form. |
Oninput |
Script |
The script that runs when the user inputs the element. |
Oninvalid |
Script |
The script that runs when the element is invalid. |
Mouse event
Events triggered by mouse or similar user actions:
Attribute |
Value |
Description |
Ondrag |
Script |
The script that runs when the element is dragged. |
Ondragend |
Script |
The script that runs at the end of the drag operation. |
Ondragenter |
Script |
The script that runs when the element has been dragged to the valid drag-and-drop area. |
Ondragleave |
Script |
The script that runs when the element leaves the valid drag-and-drop target. |
Ondragover |
Script |
The script that runs when an element is being dragged on a valid drag-and-drop target. |
Ondragstart |
Script |
The script that runs at the beginning of the drag operation. |
Ondrop |
Script |
The script that runs when the dragged element is being dragged and dropped. |
Onmousewheel |
Script |
The script that runs when the scroll wheel is being rolled. |
Onscroll |
Script |
The script that runs when the element scroll bar is rolled. |
Media events
Events triggered by media (such as video, image, and audio) (applicable to all HTML elements, but common in media elements, for example, <audio>, <embed>, , <object>, and <video> ):
Attribute |
Value |
Description |
Oncanplay |
Script |
The script that runs when the file is ready to start playing (when the buffer is enough to start ). |
Oncanplaythrough |
Script |
The script that runs when the media can stop playing to the end without buffering. |
Ondurationchange |
Script |
The script that runs when the length of the media changes. |
Onemptied |
Script |
Scripts run when a fault occurs and files are suddenly unavailable (for example, the connection is accidentally disconnected ). |
Onended |
Script |
Scripts that run when the media has reached the end (messages such as "thank you for watching" can be sent ). |
Onerror |
Script |
The script that runs when an error occurs during file loading. |
Onloadeddata |
Script |
The script that runs when media data is loaded. |
Onloadedmetadata |
Script |
The script that runs when metadata (such as resolution and duration) is loaded. |
Onloadstart |
Script |
A script that runs before the file is loaded and no data is actually loaded. |
Onpause |
Script |
The script that runs when the media is paused by the user or program. |
Onplay |
Script |
The script that runs when the media is ready to start playing. |
Onplaying |
Script |
The script that runs when the media starts playing. |
Onprogress |
Script |
The script that runs when the browser is retrieving media data. |
Onratechange |
Script |
The script that runs when the playback speed changes (for example, when the user switches to the slow action or fast forward mode ). |
Onreadystatechange |
Script |
The script that runs when the readiness status changes (the readiness status monitors the status of media data ). |
Onseeked |
Script |
The script that runs when the seeking attribute is set to false (indicating that the position has ended. |
Onseeking |
Script |
The script that runs when the seeking attribute is set to true (indicating that the location is active. |
Onstalled |
Script |
Scripts that run when the Browser fails to retrieve media data for whatever reason. |
Onsuspend |
Script |
The script that runs when retrieving media data is terminated for whatever reason before media data is fully loaded. |
Ontimeupdate |
Script |
Scripts run when the playback position changes (for example, when the user quickly enters a different position in the media. |
Onvolumechange |
Script |
The script that runs when the volume changes (including the volume is set to mute. |